Build native fnOS disk-copy application with APFS and NTFS support
这个提交包含在:
1 父节点
1f598007d1
当前提交
58769c431f
21 个文件已更改
+734
-8
没有与搜索条件相匹配的文件
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build a self-contained native fnOS FPK with the validated Linux driver."""
|
||||
from pathlib import Path
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import zlib
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
stage = ROOT / 'build/fpk'
|
||||
if stage.exists():
|
||||
shutil.rmtree(stage)
|
||||
shutil.copytree(ROOT / 'packaging/fpk', stage)
|
||||
(stage / 'wizard').mkdir(exist_ok=True)
|
||||
(stage / 'wizard/.gitkeep').touch()
|
||||
app = stage / 'app'
|
||||
for path in (ROOT / 'application').iterdir():
|
||||
if path.is_file():
|
||||
shutil.copy2(path, app / path.name)
|
||||
shutil.copy2(ROOT / 'scripts/copy-directories.py', app / 'copy_worker.py')
|
||||
shutil.copy2(ROOT / 'scripts/save-xattrs.py', app / 'save_xattrs.py')
|
||||
(app / 'bin').mkdir()
|
||||
for name, expected in [('apfs-fuse','89a7083c42fb498b021d9f7fabbc5b754eaae503649500e4926965fdcfbcb11e'),
|
||||
('apfsutil','692bbd961678c5db1a48e00cb2bc96c50e82dd77e39d87cfe11087608b4658ae')]:
|
||||
binary = ROOT / 'build/linux-bin' / name
|
||||
if hashlib.sha256(binary.read_bytes()).hexdigest() != expected:
|
||||
raise SystemExit('Driver hash mismatch: ' + name)
|
||||
shutil.copy2(binary, app / 'bin' / name)
|
||||
(app / 'bin' / name).chmod(0o755)
|
||||
shutil.copytree(ROOT / 'vendor/apfs-fuse', app / 'source/apfs-fuse')
|
||||
shutil.copy2(ROOT / 'UPSTREAM.json', app / 'source/UPSTREAM.json')
|
||||
shutil.copy2(ROOT / 'packaging/Dockerfile', app / 'source/Dockerfile')
|
||||
for path in (stage / 'cmd').iterdir():
|
||||
path.chmod(0o755)
|
||||
|
||||
|
||||
def icon(size):
|
||||
def chunk(kind, payload):
|
||||
return struct.pack('>I', len(payload)) + kind + payload + struct.pack('>I', zlib.crc32(kind + payload) & 0xffffffff)
|
||||
rows = []
|
||||
for y in range(size):
|
||||
row = bytearray()
|
||||
for x in range(size):
|
||||
px, py = x * 256 / size, y * 256 / size
|
||||
radius = 50
|
||||
dx, dy = max(abs(px - 128) - 78, 0), max(abs(py - 128) - 78, 0)
|
||||
inside = dx * dx + dy * dy <= radius * radius
|
||||
color = (22, 118, 102, 255) if inside else (0, 0, 0, 0)
|
||||
if 53 <= px <= 203 and 62 <= py <= 192 and (px < 63 or px > 193 or py < 72 or py > 182 or 144 < py < 153):
|
||||
color = (255, 255, 255, 255)
|
||||
if 78 <= px <= 90 and 164 <= py <= 172:
|
||||
color = (255, 255, 255, 255)
|
||||
if 100 <= px <= 126 and abs(py - (px - 3)) < 5 or 122 <= px <= 165 and abs(py - (249 - px)) < 5:
|
||||
color = (158, 229, 199, 255)
|
||||
row.extend(color)
|
||||
rows.append(b'\0' + row)
|
||||
return b'\x89PNG\r\n\x1a\n' + chunk(b'IHDR', struct.pack('>IIBBBBB', size, size, 8, 6, 0, 0, 0)) + chunk(b'IDAT', zlib.compress(b''.join(rows))) + chunk(b'IEND', b'')
|
||||
|
||||
|
||||
images = app / 'ui/images'
|
||||
images.mkdir(exist_ok=True)
|
||||
for size in (64, 256):
|
||||
payload = icon(size)
|
||||
(images / ('icon_' + str(size) + '.png')).write_bytes(payload)
|
||||
(stage / ('ICON.PNG' if size == 64 else 'ICON_256.PNG')).write_bytes(payload)
|
||||
subprocess.run([sys.argv[1], 'build', '--directory', str(stage)], cwd=stage, check=True)
|
||||
output = ROOT / 'dist'
|
||||
output.mkdir(exist_ok=True)
|
||||
packages = list(stage.glob('*.fpk'))
|
||||
if len(packages) != 1:
|
||||
raise SystemExit('Expected one FPK package')
|
||||
version = next(line.split('=',1)[1].strip() for line in (stage / 'manifest').read_text().splitlines() if line.startswith('version='))
|
||||
destination = output / ('dayu-diskcopy-' + version + '-x86.fpk')
|
||||
shutil.copy2(packages[0], destination)
|
||||
print(destination)
|
||||
print('sha256:', hashlib.sha256(destination.read_bytes()).hexdigest())
|
||||
+17
-7
@@ -22,7 +22,9 @@ def main():
|
||||
mount = Path(config['mount'])
|
||||
source = mount / config['source_root']
|
||||
destination = Path(config['destination']).resolve(strict=True)
|
||||
device = (Path('/dev/disk/by-partuuid') / config['partuuid']).resolve(strict=True)
|
||||
device = Path(config['device_path']).resolve(strict=True) if config.get('device_path') else (Path('/dev/disk/by-partuuid') / config['partuuid']).resolve(strict=True)
|
||||
managed = config.get('managed_mount', True)
|
||||
os.environ['LC_ALL'] = 'C'
|
||||
lock = (job.parent.parent / 'transfer.lock').open('a')
|
||||
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
state = {'pid': os.getpid(), 'started': time.time(), 'phase': 'preflight',
|
||||
@@ -48,9 +50,9 @@ def main():
|
||||
raise RuntimeError('Source is not mounted.')
|
||||
mounted = json.loads(subprocess.check_output(
|
||||
['findmnt', '-J', '-M', str(mount), '-o', 'SOURCE,OPTIONS'], text=True))['filesystems'][0]
|
||||
if Path(mounted['source']).resolve() != device or 'ro' not in mounted['options'].split(','):
|
||||
if Path(mounted['source']).resolve() != device or (managed and 'ro' not in mounted['options'].split(',')):
|
||||
raise RuntimeError('Unexpected source mount or source is not read-only.')
|
||||
if subprocess.check_output(['blockdev', '--getro', str(device)], text=True).strip() != '1':
|
||||
if managed and subprocess.check_output(['blockdev', '--getro', str(device)], text=True).strip() != '1':
|
||||
raise RuntimeError('Block device is not read-only.')
|
||||
writes_before = (Path('/sys/class/block') / device.name / 'stat').read_text().split()[4:8:2]
|
||||
state['source_write_counters_before'] = writes_before
|
||||
@@ -72,7 +74,7 @@ def main():
|
||||
(job / 'existing-files.list').write_bytes(b'\0'.join(existing) + (b'\0' if existing else b''))
|
||||
save('copying', existing_files_to_verify=len(existing), copy_started=time.time())
|
||||
source_args = [str(source / name) for name in config['directories']]
|
||||
command = ['rsync', '-rltH', '--chown=1000:1001', '--ignore-existing', '--partial',
|
||||
command = ['rsync', '-rltH', '--chown=' + str(config.get('uid', 1000)) + ':' + str(config.get('gid', 1001)), '--ignore-existing', '--partial', '--no-whole-file',
|
||||
'--partial-dir=.dayu-apfs-partial', '--info=progress2,stats2', '--outbuf=L',
|
||||
'--stats', '--no-inc-recursive', '--protect-args', *source_args, str(destination) + '/']
|
||||
result = run_to_log(command, 'copy.log')
|
||||
@@ -96,6 +98,14 @@ def main():
|
||||
*source_args, str(destination) + '/'], 'tree-check.log')
|
||||
if result or (job / 'tree-check.log').read_text().strip():
|
||||
raise RuntimeError('Final directory comparison found differences; see tree-check.log.')
|
||||
subprocess.run(['sync', '-f', str(destination)], check=True)
|
||||
metadata_helper = Path(__file__).with_name('save_xattrs.py')
|
||||
if config.get('filesystem') == 'apfs' and metadata_helper.exists():
|
||||
save('saving_metadata')
|
||||
metadata_target = destination / ('.dayu-diskcopy-metadata-' + job.name)
|
||||
result = run_to_log(['/usr/bin/python3', str(metadata_helper), str(config_path), str(metadata_target)], 'metadata-summary.json')
|
||||
if result:
|
||||
raise RuntimeError('File copy passed but extended attribute archive failed.')
|
||||
save('complete', finished=time.time(), existing_files_checksum_match=True,
|
||||
new_files_verified_by_rsync_transfer_checksums=True)
|
||||
except BaseException as error:
|
||||
@@ -103,12 +113,12 @@ def main():
|
||||
traceback.print_exc()
|
||||
finally:
|
||||
try:
|
||||
if os.path.ismount(mount):
|
||||
if managed and os.path.ismount(mount):
|
||||
subprocess.run(['umount', str(mount)], check=True, timeout=60)
|
||||
if config['original_ro'] == '0':
|
||||
if managed and config['original_ro'] == '0':
|
||||
subprocess.run(['blockdev', '--setrw', str(device)], check=True)
|
||||
writes_after = (Path('/sys/class/block') / device.name / 'stat').read_text().split()[4:8:2]
|
||||
save(state['phase'], unmounted=True, source_write_counters_after=writes_after,
|
||||
save(state['phase'], unmounted=managed and not os.path.ismount(mount), source_write_counters_after=writes_after,
|
||||
source_writes_unchanged=writes_after == state.get('source_write_counters_before'))
|
||||
except BaseException as error:
|
||||
save('cleanup_failed', prior_phase=state['phase'], cleanup_error=str(error))
|
||||
|
||||
在新工单中引用
屏蔽一个用户