Skip to content

Commit 5460b52

Browse files
committed
Add a test checking that unlinking the first inode frees it
1 parent 05f6b62 commit 5460b52

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Tests/ContainerizationEXT4Tests/TestEXT4Format+Link.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,19 @@ struct Ext4FormatLinkTests {
4242
let afterUnlink = try makeFile(unlink: true)
4343
#expect(try EXT4.EXT4Reader(blockDevice: afterUnlink).stat("/original").inode.linksCount == 1)
4444
}
45+
46+
@Test func unlinkFirstInodeFreesInode() throws {
47+
let emptyPath = FilePath(FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: false))
48+
defer { try? FileManager.default.removeItem(at: emptyPath.url) }
49+
try EXT4.Formatter(emptyPath, minDiskSize: 32.kib()).close()
50+
51+
let path = FilePath(FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: false))
52+
defer { try? FileManager.default.removeItem(at: path.url) }
53+
let fmt = try EXT4.Formatter(path, minDiskSize: 32.kib())
54+
try fmt.create(path: FilePath("/file"), mode: EXT4.Inode.Mode(.S_IFREG, 0o755), buf: nil)
55+
try fmt.unlink(path: FilePath("/file"))
56+
try fmt.close()
57+
58+
#expect(try EXT4.EXT4Reader(blockDevice: path).superBlock.freeInodesCount == EXT4.EXT4Reader(blockDevice: emptyPath).superBlock.freeInodesCount)
59+
}
4560
}

0 commit comments

Comments
 (0)