NIOFileSystem: Add on-disk size to FileInfo - #3656
Conversation
| XCTAssertEqual(info.userID, FileInfo.UserID(rawValue: 5)) | ||
| XCTAssertEqual(info.groupID, FileInfo.GroupID(rawValue: 6)) | ||
| XCTAssertEqual(info.size, 8) | ||
| XCTAssertEqual(info.onDiskSize, 9 * 512) |
There was a problem hiding this comment.
could we maybe add a test case which creates a file with a hole? Should be pretty easy: FileSystem.shared.withFileOpen(forWriting: ".../stuff") { handle in handle.write("hi"); handle.resize(128 MB) } then check that the on-disk size is under 1MB for UNIX platforms
There was a problem hiding this comment.
Added an integration regression test that writes hi, resizes the file to 128 MiB, and verifies the logical size while asserting the on-disk allocation remains below 1 MiB.
| private let S_BLKSIZE = Musl.DEV_BSIZE | ||
| #elseif canImport(Android) | ||
| private let S_BLKSIZE = Android.S_BLKSIZE | ||
| #endif |
There was a problem hiding this comment.
@jakepetroules To avoid an in-flight regression of Windows, can you identify what the appropriate operation is there?
There was a problem hiding this comment.
I checked the Windows port. The corresponding API for actual allocated bytes is GetCompressedFileSizeW. Because FileInfo currently receives only BY_HANDLE_FILE_INFORMATION while that API is path-based, I need to thread the value through the path/handle information flow and add a Windows sparse-file test rather than add an inaccurate fallback.
|
Small correction to my previous reply: The newly landed NIOFileSystem Windows port is currently compile-only and its PR #3668 currently takes the optional/ |
I think you can |
1ef50f0 to
93757ec
Compare
|
Thanks. I’ve rebased onto the current The focused Could you please trigger CI and re-review when convenient? |
Summary
Add
FileInfo.onDiskSizeso callers can retrieve the number of bytes a file actually occupies on disk, independently of its apparent size.This is useful for sparse and compressed files, where
FileInfo.sizecan differ significantly from the allocated storage.Fixes #3650.
Changes
FileInfo.onDiskSizeproperty to bothNIOFSand_NIOFileSystem.S_BLKSIZE * stat.st_blocks, without usingstat.st_blksize.DEV_BSIZEconstant whereS_BLKSIZEis unavailable.FileInfoinitializer with anonDiskSizeargument.st_blksizeis set to 10.Testing
swift test --jobs 2 --filter NIOFSTests.FileInfoTestsswift test --skip-build --filter NIOFSTestsswift format lint --strict --configuration .swift-format Sources/NIOFS/FileInfo.swift Sources/_NIOFileSystem/FileInfo.swift Tests/NIOFSTests/FileInfoTests.swiftgit diff --check