Refine job estimates, mount cleanup and NTFS identification tests
这个提交包含在:
1 父节点
58769c431f
当前提交
12df14ebf0
4 个文件已更改
+42
-5
没有与搜索条件相匹配的文件
+2
@@ -11,6 +11,8 @@
|
|||||||
- NAS 已核实为 fnOS `1.2.0701`,有 ntfs-3g、mkntfs、ntfscp。NTFS 已有系统挂载时优先复用,应用只读取源文件;不强行卸载或修改系统在用盘。未挂载的新盘使用只读挂载。
|
- NAS 已核实为 fnOS `1.2.0701`,有 ntfs-3g、mkntfs、ntfscp。NTFS 已有系统挂载时优先复用,应用只读取源文件;不强行卸载或修改系统在用盘。未挂载的新盘使用只读挂载。
|
||||||
- 应用第一版代码位于 `application/`,FPK 定义在 `packaging/fpk/`,构建入口 `scripts/build-fpk.py`。当前版本 0.1.0;使用官方网关 Unix Socket,不开放新的网络端口。Web 进程启动后降为专用包用户,原始设备操作由本机 Socket 服务处理并核验调用 UID。
|
- 应用第一版代码位于 `application/`,FPK 定义在 `packaging/fpk/`,构建入口 `scripts/build-fpk.py`。当前版本 0.1.0;使用官方网关 Unix Socket,不开放新的网络端口。Web 进程启动后降为专用包用户,原始设备操作由本机 Socket 服务处理并核验调用 UID。
|
||||||
- 已通过五项边界测试:匿名及非管理员拒绝、管理员页面可读、写请求来源校验、路径穿越和符号链接越界拒绝、系统身份拒绝;Python/生命周期脚本语法通过。FPK 构建和实机界面/NTFS 镜像验证正在进行,尚未宣称正式交付。
|
- 已通过五项边界测试:匿名及非管理员拒绝、管理员页面可读、写请求来源校验、路径穿越和符号链接越界拒绝、系统身份拒绝;Python/生命周期脚本语法通过。FPK 构建和实机界面/NTFS 镜像验证正在进行,尚未宣称正式交付。
|
||||||
|
- 0.1.0 已实际安装并启动:官方网关登录态生效,浏览器可浏览 APFS 目录并显示当前后台任务;Web 进程实际 UID 985(非 root),设备服务为 root,两个 Unix Socket 均为 0660。
|
||||||
|
- 新版 0.1.1 修正根目录显示、平滑速度/剩余时间估算,并在服务退出时清理应用闲置挂载(不影响正在拷贝的盘)。七项边界测试通过;NTFS 64 MiB 自建镜像只读挂载、1 MiB 文件复制 SHA-256 比对已通过,无实体 NTFS USB 盘测试。0.1.1 待升级并做最终端到端 UI 复制验证。
|
||||||
|
|
||||||
## 当前复制任务(2026-11-11 22:36 启动)
|
## 当前复制任务(2026-11-11 22:36 启动)
|
||||||
|
|
||||||
|
|||||||
+22
-4
@@ -21,6 +21,7 @@ APP_UID = int(os.environ['TRIM_UID'])
|
|||||||
APP_GID = int(os.environ['TRIM_GID'])
|
APP_GID = int(os.environ['TRIM_GID'])
|
||||||
LEGACY = Path('/var/tmp/dayu-apfs-validation')
|
LEGACY = Path('/var/tmp/dayu-apfs-validation')
|
||||||
TERMINAL = {'complete', 'failed', 'needs_attention', 'cleanup_failed', 'cancelled'}
|
TERMINAL = {'complete', 'failed', 'needs_attention', 'cleanup_failed', 'cancelled'}
|
||||||
|
HISTORY = {}
|
||||||
|
|
||||||
|
|
||||||
def command(args, timeout=30):
|
def command(args, timeout=30):
|
||||||
@@ -95,9 +96,13 @@ def jobs(uid=None):
|
|||||||
if phase == 'complete' and 'source_write_counters_after' not in state:
|
if phase == 'complete' and 'source_write_counters_after' not in state:
|
||||||
phase = 'finalizing'
|
phase = 'finalizing'
|
||||||
speed = 0
|
speed = 0
|
||||||
if progress and phase == 'copying':
|
if phase == 'copying':
|
||||||
multiplier = 1024 ** ('kMGT'.find(progress[-1][4]) + 1) if progress[-1][4] else 1
|
now = time.time()
|
||||||
speed = float(progress[-1][3]) * multiplier
|
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)
|
total = config.get('planned_copy_bytes', 0)
|
||||||
if phase == 'complete':
|
if phase == 'complete':
|
||||||
copied = total
|
copied = total
|
||||||
@@ -178,13 +183,14 @@ def target_path(path, uid, must_exist=True):
|
|||||||
|
|
||||||
|
|
||||||
def listing(root, relative=''):
|
def listing(root, relative=''):
|
||||||
|
root = root.resolve(strict=True)
|
||||||
path = beneath(root / relative, root)
|
path = beneath(root / relative, root)
|
||||||
entries = []
|
entries = []
|
||||||
for entry in path.iterdir():
|
for entry in path.iterdir():
|
||||||
if entry.name.startswith('.') or entry.is_symlink() or not entry.is_dir():
|
if entry.name.startswith('.') or entry.is_symlink() or not entry.is_dir():
|
||||||
continue
|
continue
|
||||||
entries.append({'name': entry.name, 'path': str(entry.relative_to(root))})
|
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):
|
def dispatch(request):
|
||||||
@@ -311,3 +317,15 @@ if __name__ == '__main__':
|
|||||||
finally:
|
finally:
|
||||||
server.server_close()
|
server.server_close()
|
||||||
path.unlink(missing_ok=True)
|
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
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
appname=dayu-diskcopy
|
appname=dayu-diskcopy
|
||||||
version=0.1.0
|
version=0.1.1
|
||||||
display_name=大鱼硬盘拷贝
|
display_name=大鱼硬盘拷贝
|
||||||
desc=直接读取 APFS、NTFS 外接硬盘,在飞牛 NAS 本机后台拷贝目录、查看进度和校验结果。
|
desc=直接读取 APFS、NTFS 外接硬盘,在飞牛 NAS 本机后台拷贝目录、查看进度和校验结果。
|
||||||
source=thirdparty
|
source=thirdparty
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import socket
|
|||||||
import tempfile
|
import tempfile
|
||||||
import threading
|
import threading
|
||||||
import unittest
|
import unittest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
ROOT = Path(__file__).resolve().parents[1]
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
|
||||||
@@ -39,6 +40,22 @@ class PathBoundaryTests(unittest.TestCase):
|
|||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
broker.dispatch({'uid': 0, 'action': 'start', 'args': {}})
|
broker.dispatch({'uid': 0, 'action': 'start', 'args': {}})
|
||||||
|
|
||||||
|
def test_usb_apfs_ntfs_identified_and_internal_disks_excluded(self):
|
||||||
|
broker = module('broker')
|
||||||
|
tree = {'blockdevices': [
|
||||||
|
{'tran': 'usb', 'size': 1000, 'serial': 'usb1', 'model': 'Test', 'children': [
|
||||||
|
{'path': '/dev/test1', 'size': 900, 'fstype': 'ntfs', 'partuuid': 'abc', 'mountpoints': []},
|
||||||
|
{'path': '/dev/test2', 'size': 100, 'fstype': 'apfs', 'partuuid': 'def', 'mountpoints': []}]},
|
||||||
|
{'tran': 'sata', 'size': 1000, 'serial': 'system', 'fstype': 'ntfs'}]}
|
||||||
|
with patch.object(broker, 'command', return_value=json.dumps(tree)):
|
||||||
|
detected = broker.disks()
|
||||||
|
self.assertEqual([item['filesystem'] for item in detected], ['ntfs', 'apfs'])
|
||||||
|
|
||||||
|
def test_root_listing_uses_empty_relative_path(self):
|
||||||
|
broker = module('broker')
|
||||||
|
with tempfile.TemporaryDirectory() as folder:
|
||||||
|
self.assertEqual(broker.listing(Path(folder))['path'], '')
|
||||||
|
|
||||||
|
|
||||||
class GatewayTests(unittest.TestCase):
|
class GatewayTests(unittest.TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户