Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-model
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Renaud Boyer
swh-model
Commits
dca0eafa
Verified
Commit
dca0eafa
authored
8 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
swh.model.git - update - Secure paths removal
parent
0fbf74e0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
swh/model/git.py
+34
-8
34 additions, 8 deletions
swh/model/git.py
with
34 additions
and
8 deletions
swh/model/git.py
+
34
−
8
View file @
dca0eafa
...
...
@@ -384,6 +384,32 @@ def commonpath(paths):
raise
def
__remove_paths_from_objects
(
objects
,
rootpaths
):
"""
Given top paths to remove, remove all paths and descendants from
objects.
Args:
objects: The dictionary of paths to clean up.
rootpaths: The rootpaths to remove from objects.
Returns:
Objects dictionary without the rootpaths and their descendants.
"""
child_dirpaths
=
[]
for
path
in
rootpaths
:
path_list
=
objects
.
pop
(
path
,
None
)
if
path_list
:
# need to remove the children directories too
for
child
in
path_list
:
if
child
[
'
type
'
]
==
GitType
.
TREE
:
child_dirpaths
.
append
(
child
[
'
path
'
])
if
child_dirpaths
:
objects
=
__remove_paths_from_objects
(
objects
,
child_dirpaths
)
return
objects
def
update_checksums_from
(
changed_paths
,
objects
,
dir_ok_fn
=
lambda
dirpath
:
True
):
"""
Given a list of changed paths, recompute the checksums only where
...
...
@@ -405,7 +431,8 @@ def update_checksums_from(changed_paths, objects,
if
root
.
endswith
(
b
'
/
'
):
root
=
root
.
rstrip
(
b
'
/
'
)
paths
=
[]
paths
=
[]
# contain the list of impacted paths (A, D, M)
paths_to_remove
=
[]
# will contain the list of deletion paths (only D)
# a first round-trip to ensure we don't need to...
for
changed_path
in
changed_paths
:
path
=
changed_path
[
'
path
'
]
...
...
@@ -416,16 +443,12 @@ def update_checksums_from(changed_paths, objects,
dir_ok_fn
)
if
changed_path
[
'
action
'
]
==
'
D
'
:
# (D)elete
k
=
objects
.
pop
(
path
,
None
)
if
k
:
# it's a dir, we need to remove the descendant paths
prefix_path
=
path
+
b
'
/
'
new_objects
=
{
k
:
objects
[
k
]
for
k
in
objects
.
keys
()
if
not
k
.
startswith
(
prefix_path
)}
objects
=
new_objects
paths_to_remove
.
append
(
path
)
paths
.
append
(
parent
)
if
not
paths
:
# no modification on paths
# no modification on paths (paths also contain deletion paths if any)
if
not
paths
:
return
objects
rootdir
=
commonpath
(
paths
)
...
...
@@ -436,6 +459,9 @@ def update_checksums_from(changed_paths, objects,
return
walk_and_compute_sha1_from_directory
(
root
,
dir_ok_fn
)
# Now we can remove the deleted directories from objects dictionary
objects
=
__remove_paths_from_objects
(
objects
,
paths_to_remove
)
# Recompute from disk the checksums from impacted common ancestor
# rootdir changes. Then update the original objects with new
# checksums for the arborescence tree below rootdir
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment