Skip to content

Commit

Permalink
Avoid duplicating children, omit frozen detection for now
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Dick committed Feb 3, 2024
1 parent cffca71 commit d10c0c0
Showing 1 changed file with 22 additions and 33 deletions.
55 changes: 22 additions & 33 deletions perfact/zodbsync/zodbsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ def fs_pathinfo(self, path):
The topmost remaining layer that has a __meta__ file is the one we
want.
The children are collected from the subfolders of all remaining layers.
TODO: This does not currently search for __frozen__ markers. We need to
find a more efficient way, maybe searching them once at the beginning.
Return value:
{
'path': Original argument
Expand All @@ -374,40 +376,27 @@ def fs_pathinfo(self, path):
'fspath': None,
'children': [],
}

# These are in reverse order, the topmost layer has index 0
layers = [
{'fspath': layer['base_dir'], 'children': self.site}
for layer in reversed(self.layers)
]

for part in [self.site] + path.split('/'):
if not part:
continue
next_layers = []
for layer in layers:
if part not in layer['children']:
# Folder does not exist, this layer is irrelevant
continue
fspath = os.path.join(layer['fspath'], part)
children = os.listdir(fspath)
next_layers.append({'fspath': fspath, 'children': children})
if '__frozen__' in children:
# Mask all lower layers
break
layers = next_layers

layers_with_meta = [
layer for layer in layers if '__meta__' in layer['children']
path = path.lstrip('/')
fspaths = list(filter(os.path.isdir, [
os.path.join(layer['base_dir'], self.site, path)
for layer in self.layers
]))
with_meta = [
fspath for fspath in fspaths
if os.path.exists(os.path.join(fspath, '__meta__'))
]
if layers_with_meta:
result['fspath'] = layers_with_meta[0]['fspath']
all_children = sum((layer['children'] for layer in layers),
start=[])
result['children'] = [
child for child in all_children
if not child.startswith('__')
]
if not with_meta:
return result
all_children = sum(
[os.listdir(fspath) for fspath in fspaths],
start=[],
)
result.update({
'fspath': with_meta[-1],
'children': sorted({
child for child in all_children if not child.startswith('__')
}),
})
return result

def fs_write(self, path, data):
Expand Down

0 comments on commit d10c0c0

Please sign in to comment.