parent
712731f4fe
commit
6480a51a82
2 changed files with 8 additions and 6 deletions
|
@ -194,6 +194,10 @@ def load_state(statefile: Path) -> Vfs:
|
|||
return oldfs
|
||||
|
||||
|
||||
def remove_all(l, it):
|
||||
return [i for i in l if i != it]
|
||||
|
||||
|
||||
def simplify(old_fs: Vfs, new_fs: Vfs, /, exec_idempotent=True) -> Vfs:
|
||||
"""Try to reduce a new VFS using diff from the original VFS."""
|
||||
|
||||
|
@ -202,15 +206,12 @@ def simplify(old_fs: Vfs, new_fs: Vfs, /, exec_idempotent=True) -> Vfs:
|
|||
initial_new_steps = len(new_fs._log)
|
||||
|
||||
# Scrub anything in the new log that's in the old log
|
||||
for txn in list(old_fs._log):
|
||||
for txn in old_fs._log:
|
||||
# Except for execs which are stateful
|
||||
if txn[0] == "exec" and not exec_idempotent:
|
||||
continue
|
||||
|
||||
try:
|
||||
new_fs._log.remove(txn)
|
||||
except ValueError:
|
||||
pass
|
||||
new_fs._log = remove_all(new_fs._log, txn)
|
||||
|
||||
# Dedupe the new log while preserving order.
|
||||
keys = set()
|
||||
|
@ -220,6 +221,7 @@ def simplify(old_fs: Vfs, new_fs: Vfs, /, exec_idempotent=True) -> Vfs:
|
|||
if key not in keys:
|
||||
keys.add(key)
|
||||
deduped.append(op)
|
||||
|
||||
new_fs._log = deduped
|
||||
|
||||
log.info(f"Optimized out {initial_new_steps - len(new_fs._log)} steps")
|
||||
|
|
|
@ -49,8 +49,8 @@ def stow(fs: Vfs, src_dir: Path, dest_dir: Path, skip=[]):
|
|||
|
||||
dest = dest_root / src.relative_to(src_root)
|
||||
if src.is_symlink():
|
||||
|
||||
fs.link(src.readlink().resolve(), dest)
|
||||
|
||||
elif src.is_dir():
|
||||
fs.mkdir(dest)
|
||||
fs.chmod(dest, src.stat().st_mode)
|
||||
|
|
Loading…
Reference in a new issue