module engine import os struct SpaceFailureTrace { mut: lines []string } fn space_failure_log(context voidptr, level LogLevel, message string) { mut trace := unsafe { &SpaceFailureTrace(context) } trace.lines << '${u32(level)}:${message}' } fn test_unavailable_filesystem_logs_once_without_replacing_previous_error() ! { base := os.join_path(os.vtmp_dir(), 'alpm-space-failure-${os.getpid()}') os.mkdir_all(base)! defer { os.rmdir_all(base) or { eprintln(err) } } mut handle := initialize('/', base)! defer { handle.release() or { eprintln(err) } } mut trace := SpaceFailureTrace{} handle.set_log_callback(space_failure_log, &trace)! if _ := handle.register_syncdb('', 0) { assert false } mut mount := InstallationMount{ path: os.join_path(base, 'absent') } assert !handle.load_installation_mount(mut mount) assert mount.loaded && mount.failed assert handle.errno() == .wrong_args assert trace.lines == ['2:could not get filesystem information for ${mount.path}: No such file or directory\n'] assert !handle.load_installation_mount(mut mount) assert trace.lines.len == 1 assert handle.errno() == .wrong_args } fn test_partition_space_threshold_and_overflow_guard() ! { base := os.join_path(os.vtmp_dir(), 'alpm-space-threshold-${os.getpid()}') os.mkdir_all(base)! defer { os.rmdir_all(base) or { eprintln(err) } } mut handle := initialize('/', base)! defer { handle.release() or { eprintln(err) } } mut trace := SpaceFailureTrace{} handle.set_log_callback(space_failure_log, &trace)! mut mount := InstallationMount{ path: '/fixture' info: C.v_alpm_space_info{ block_size: 4096, blocks: 10000, available: 506 } maximum_needed: 5 } assert !handle.space_mount_full(mount)! mount.info.available-- assert handle.space_mount_full(mount)! assert trace.lines == [ '4:partition /fixture, needed 5, cushion 501, free 506\n', '4:partition /fixture, needed 5, cushion 501, free 505\n', '1:Partition /fixture too full: 506 blocks needed, 505 blocks free\n', ] mount.maximum_needed = max_i64 if _ := handle.space_mount_full(mount) { assert false } assert handle.errno() == .disk_space }