Refine job estimates, mount cleanup and NTFS identification tests
这个提交包含在:
1 父节点
58769c431f
当前提交
12df14ebf0
4 个文件已更改
+42
-5
没有与搜索条件相匹配的文件
+22
-4
@@ -21,6 +21,7 @@ APP_UID = int(os.environ['TRIM_UID'])
|
||||
APP_GID = int(os.environ['TRIM_GID'])
|
||||
LEGACY = Path('/var/tmp/dayu-apfs-validation')
|
||||
TERMINAL = {'complete', 'failed', 'needs_attention', 'cleanup_failed', 'cancelled'}
|
||||
HISTORY = {}
|
||||
|
||||
|
||||
def command(args, timeout=30):
|
||||
@@ -95,9 +96,13 @@ def jobs(uid=None):
|
||||
if phase == 'complete' and 'source_write_counters_after' not in state:
|
||||
phase = 'finalizing'
|
||||
speed = 0
|
||||
if progress and phase == 'copying':
|
||||
multiplier = 1024 ** ('kMGT'.find(progress[-1][4]) + 1) if progress[-1][4] else 1
|
||||
speed = float(progress[-1][3]) * multiplier
|
||||
if phase == 'copying':
|
||||
now = time.time()
|
||||
samples = HISTORY.setdefault(str(folder), [])
|
||||
samples.append((now, copied))
|
||||
samples[:] = [sample for sample in samples if sample[0] >= now - 90]
|
||||
elapsed = now - samples[0][0]
|
||||
speed = (copied - samples[0][1]) / elapsed if elapsed >= 15 else copied / max(1, now - state.get('copy_started', now))
|
||||
total = config.get('planned_copy_bytes', 0)
|
||||
if phase == 'complete':
|
||||
copied = total
|
||||
@@ -178,13 +183,14 @@ def target_path(path, uid, must_exist=True):
|
||||
|
||||
|
||||
def listing(root, relative=''):
|
||||
root = root.resolve(strict=True)
|
||||
path = beneath(root / relative, root)
|
||||
entries = []
|
||||
for entry in path.iterdir():
|
||||
if entry.name.startswith('.') or entry.is_symlink() or not entry.is_dir():
|
||||
continue
|
||||
entries.append({'name': entry.name, 'path': str(entry.relative_to(root))})
|
||||
return {'path': str(path.relative_to(root)), 'entries': sorted(entries, key=lambda item: item['name'].casefold())}
|
||||
return {'path': '' if path == root else str(path.relative_to(root)), 'entries': sorted(entries, key=lambda item: item['name'].casefold())}
|
||||
|
||||
|
||||
def dispatch(request):
|
||||
@@ -311,3 +317,15 @@ if __name__ == '__main__':
|
||||
finally:
|
||||
server.server_close()
|
||||
path.unlink(missing_ok=True)
|
||||
in_use = {job['device_id'] for job in active()}
|
||||
for identity, item in mounts().items():
|
||||
if identity in in_use or not item.get('managed'):
|
||||
continue
|
||||
try:
|
||||
if os.path.ismount(item['mount']):
|
||||
command(['umount', item['mount']])
|
||||
properties = command(['udevadm', 'info', '-q', 'property', '-n', item['device']])
|
||||
if ('ID_SERIAL_SHORT=' + item['serial']) in properties.splitlines() and item['original_ro'] == '0':
|
||||
command(['blockdev', '--setrw', item['device']])
|
||||
except Exception:
|
||||
pass
|
||||
在新工单中引用
屏蔽一个用户