| 1 | module engine |
| 2 | |
| 3 | import os |
| 4 | |
| 5 | fn test_legacy_validation_marker_survives_local_reason_rewrites() ! { |
| 6 | base := os.join_path(os.vtmp_dir(), 'legacy-md5-history-${os.getpid()}') |
| 7 | entry := os.join_path(base, 'local', 'p-1-1') |
| 8 | os.mkdir_all(entry)! |
| 9 | defer { os.rmdir_all(base) or { eprintln(err) } } |
| 10 | os.write_file(os.join_path(base, 'local', 'ALPM_DB_VERSION'), '9\n')! |
| 11 | os.write_file(os.join_path(entry, 'desc'), '%REASON%\n0\n\n%VALIDATION%\nmd5\nsha256\npgp\n\n')! |
| 12 | mut handle := initialize('/', base)! |
| 13 | mut db := handle.local_database()! |
| 14 | mut pkg := db.get_pkg('p') or { return error('missing local package') } |
| 15 | pkg.load_description()! |
| 16 | assert pkg.validation == 14 |
| 17 | assert !pkg.diagnostics.any(it.contains('unknown validation type')) |
| 18 | pkg.set_reason(.depend)! |
| 19 | handle.release()! |
| 20 | assert os.read_file(os.join_path(entry, 'desc'))!.contains('%VALIDATION%\nmd5\nsha256\npgp\n\n') |
| 21 | mut reopened := initialize('/', base)! |
| 22 | defer { reopened.release() or { eprintln(err) } } |
| 23 | mut local := reopened.local_database()! |
| 24 | mut saved := local.get_pkg('p') or { return error('missing saved package') } |
| 25 | saved.load_description()! |
| 26 | assert saved.reason == .depend |
| 27 | assert saved.validation == 14 |
| 28 | } |
| 29 | |
| 30 | fn test_legacy_md5_lookup_rejects_a_missing_filename_and_preserves_read_errors() ! { |
| 31 | base := os.join_path(os.vtmp_dir(), 'legacy-md5-boundaries-${os.getpid()}') |
| 32 | os.mkdir_all(base)! |
| 33 | defer { os.rmdir_all(base) or { eprintln(err) } } |
| 34 | mut handle := initialize('/', base)! |
| 35 | defer { handle.release() or { eprintln(err) } } |
| 36 | mut pkg := &Package{ origin: .sync_db, owner: handle, has_md5sum: true, md5sum: 'd41d8cd98f00b204e9800998ecf8427e' } |
| 37 | assert handle.check_package_md5sum(pkg) == -1 |
| 38 | assert handle.errno() == .wrong_args |
| 39 | pkg.filename = 'unreadable' |
| 40 | pkg.has_filename = true |
| 41 | path := os.join_path(base, 'unreadable') |
| 42 | os.write_file(path, 'content')! |
| 43 | handle.add_string_list(.cache_dirs, base)! |
| 44 | if C.geteuid() != 0 { |
| 45 | os.chmod(path, 0)! |
| 46 | defer { os.chmod(path, 0o600) or { eprintln(err) } } |
| 47 | assert handle.check_package_md5sum(pkg) == -1 |
| 48 | // the legacy integer API reports an unavailable digest without an errno. |
| 49 | assert handle.errno() == .ok |
| 50 | } |
| 51 | } |
| 52 | |