56 lines
No EOL
1.2 KiB
Python
56 lines
No EOL
1.2 KiB
Python
import marisa_trie
|
|
import os
|
|
|
|
|
|
AUFS_METADATA = u'.wh..wh.'
|
|
|
|
AUFS_WHITEOUT = u'.wh.'
|
|
AUFS_WHITEOUT_PREFIX_LENGTH = len(AUFS_WHITEOUT)
|
|
|
|
|
|
def files_and_dirs(root_path, removed_prefix_collector):
|
|
for root, dirs, files in os.walk(unicode(root_path)):
|
|
|
|
rel_root = os.path.relpath(root, root_path)
|
|
yield rel_root
|
|
|
|
for one_file in files:
|
|
if one_file.startswith(AUFS_METADATA):
|
|
# Skip
|
|
continue
|
|
|
|
elif one_file.startswith(AUFS_WHITEOUT):
|
|
filename = one_file[AUFS_WHITEOUT_PREFIX_LENGTH:]
|
|
removed_prefix_collector.add(os.path.join(rel_root, filename))
|
|
continue
|
|
|
|
else:
|
|
yield os.path.join(rel_root, one_file)
|
|
|
|
|
|
def compute_removed(base_trie, removed_prefixes):
|
|
for prefix in removed_prefixes:
|
|
for filename in base_trie.keys(prefix):
|
|
yield filename
|
|
|
|
|
|
def compute_added_changed(base_trie, delta_trie):
|
|
added = set()
|
|
changed = set()
|
|
|
|
for filename in delta_trie.keys():
|
|
if filename not in base_trie:
|
|
added.add(filename)
|
|
else:
|
|
changed.add(filename)
|
|
|
|
return added, changed
|
|
|
|
|
|
def new_fs(base_trie, added, removed):
|
|
for filename in base_trie.keys():
|
|
if filename not in removed:
|
|
yield filename
|
|
|
|
for filename in added:
|
|
yield filename |