From 527a3aa8e12dd85d77c690d57e215f7717ebab2c Mon Sep 17 00:00:00 2001 From: Dmitry Kovba Date: Wed, 8 Apr 2026 13:16:44 -0700 Subject: [PATCH 1/6] Add a test for paths under the absolute root --- .../TestEXT4Reader+IO.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Tests/ContainerizationEXT4Tests/TestEXT4Reader+IO.swift b/Tests/ContainerizationEXT4Tests/TestEXT4Reader+IO.swift index 5a7739523..a350beeef 100644 --- a/Tests/ContainerizationEXT4Tests/TestEXT4Reader+IO.swift +++ b/Tests/ContainerizationEXT4Tests/TestEXT4Reader+IO.swift @@ -584,4 +584,20 @@ struct EXT4PathIOTests { let all = try r.readFile(at: FilePath("/big/file.bin")) #expect(all.count == bigSize) } + + @Test + func fileTreeNodePathWithAbsoluteRoot() { + let tree = EXT4.FileTree(EXT4.RootInode, "/") + + let dirPtr = EXT4.Ptr.allocate(capacity: 1) + dirPtr.initialize(to: EXT4.FileTree.FileTreeNode(inode: 3, name: "dir", parent: tree.root)) + tree.root.pointee.children.append(dirPtr) + + let filePtr = EXT4.Ptr.allocate(capacity: 1) + filePtr.initialize(to: EXT4.FileTree.FileTreeNode(inode: 4, name: "file", parent: dirPtr)) + dirPtr.pointee.children.append(filePtr) + + #expect(dirPtr.pointee.path == FilePath("/dir")) + #expect(filePtr.pointee.path == FilePath("/dir/file")) + } } From 80a794f1a7fd8fa234271ef8fc34bdc37803633f Mon Sep 17 00:00:00 2001 From: Dmitry Kovba Date: Wed, 8 Apr 2026 13:20:20 -0700 Subject: [PATCH 2/6] Add a test for paths under the relative root --- .../TestEXT4Reader+IO.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Tests/ContainerizationEXT4Tests/TestEXT4Reader+IO.swift b/Tests/ContainerizationEXT4Tests/TestEXT4Reader+IO.swift index a350beeef..b9c0d0a82 100644 --- a/Tests/ContainerizationEXT4Tests/TestEXT4Reader+IO.swift +++ b/Tests/ContainerizationEXT4Tests/TestEXT4Reader+IO.swift @@ -600,4 +600,20 @@ struct EXT4PathIOTests { #expect(dirPtr.pointee.path == FilePath("/dir")) #expect(filePtr.pointee.path == FilePath("/dir/file")) } + + @Test + func fileTreeNodePathWithRelativeRoot() { + let tree = EXT4.FileTree(EXT4.RootInode, ".") + + let dirPtr = EXT4.Ptr.allocate(capacity: 1) + dirPtr.initialize(to: EXT4.FileTree.FileTreeNode(inode: 3, name: "dir", parent: tree.root)) + tree.root.pointee.children.append(dirPtr) + + let filePtr = EXT4.Ptr.allocate(capacity: 1) + filePtr.initialize(to: EXT4.FileTree.FileTreeNode(inode: 4, name: "file", parent: dirPtr)) + dirPtr.pointee.children.append(filePtr) + + #expect(dirPtr.pointee.path == FilePath("dir")) + #expect(filePtr.pointee.path == FilePath("dir/file")) + } } From 718578068c1b5563fd8f424fbf156f21fb85c1b3 Mon Sep 17 00:00:00 2001 From: Dmitry Kovba Date: Wed, 8 Apr 2026 13:27:21 -0700 Subject: [PATCH 3/6] Add a test for a path under a named root --- .../ContainerizationEXT4Tests/TestEXT4Reader+IO.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Tests/ContainerizationEXT4Tests/TestEXT4Reader+IO.swift b/Tests/ContainerizationEXT4Tests/TestEXT4Reader+IO.swift index b9c0d0a82..d987d9a00 100644 --- a/Tests/ContainerizationEXT4Tests/TestEXT4Reader+IO.swift +++ b/Tests/ContainerizationEXT4Tests/TestEXT4Reader+IO.swift @@ -616,4 +616,15 @@ struct EXT4PathIOTests { #expect(dirPtr.pointee.path == FilePath("dir")) #expect(filePtr.pointee.path == FilePath("dir/file")) } + + @Test + func fileTreeNodePathWithNamedRoot() { + let tree = EXT4.FileTree(EXT4.RootInode, "dir") + + let filePtr = EXT4.Ptr.allocate(capacity: 1) + filePtr.initialize(to: EXT4.FileTree.FileTreeNode(inode: 3, name: "file", parent: tree.root)) + tree.root.pointee.children.append(filePtr) + + #expect(filePtr.pointee.path == FilePath("dir/file")) + } } From 2a45298953445f752c39e7d0ee06060d20e1e398 Mon Sep 17 00:00:00 2001 From: Dmitry Kovba Date: Wed, 8 Apr 2026 13:34:10 -0700 Subject: [PATCH 4/6] Fix the path by reversing the order of the pushing operation --- Sources/ContainerizationEXT4/EXT4+FileTree.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ContainerizationEXT4/EXT4+FileTree.swift b/Sources/ContainerizationEXT4/EXT4+FileTree.swift index d8fa8cbc1..a1c3a82cf 100644 --- a/Sources/ContainerizationEXT4/EXT4+FileTree.swift +++ b/Sources/ContainerizationEXT4/EXT4+FileTree.swift @@ -75,7 +75,7 @@ extension EXT4 { guard let dataPath = String(data: data, encoding: .utf8) else { return nil } - return FilePath(dataPath).pushing(FilePath(last)).lexicallyNormalized() + return FilePath(last).pushing(FilePath(dataPath)).lexicallyNormalized() } } From d9a69585e186fbc4f71bc52dabc2459d639fc223 Mon Sep 17 00:00:00 2001 From: Dmitry Kovba Date: Wed, 8 Apr 2026 13:53:21 -0700 Subject: [PATCH 5/6] Remove the unnecessary handling of the last component --- Sources/ContainerizationEXT4/EXT4+FileTree.swift | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Sources/ContainerizationEXT4/EXT4+FileTree.swift b/Sources/ContainerizationEXT4/EXT4+FileTree.swift index a1c3a82cf..8cbc5d154 100644 --- a/Sources/ContainerizationEXT4/EXT4+FileTree.swift +++ b/Sources/ContainerizationEXT4/EXT4+FileTree.swift @@ -61,13 +61,6 @@ extension EXT4 { components.append(ptr.pointee.name) _ptr = ptr.pointee.parent } - guard let last = components.last else { - return nil - } - guard components.count > 1 else { - return FilePath(last) - } - components = components.dropLast() let path = components.reversed().joined(separator: "/") guard let data = path.data(using: .utf8) else { return nil @@ -75,7 +68,7 @@ extension EXT4 { guard let dataPath = String(data: data, encoding: .utf8) else { return nil } - return FilePath(last).pushing(FilePath(dataPath)).lexicallyNormalized() + return FilePath(dataPath).lexicallyNormalized() } } From 25ec59a994207743e60a86ef860fe99ec12f9765 Mon Sep 17 00:00:00 2001 From: Dmitry Kovba Date: Wed, 8 Apr 2026 13:54:26 -0700 Subject: [PATCH 6/6] Remove the unnecessary round-trip conversions --- Sources/ContainerizationEXT4/EXT4+FileTree.swift | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Sources/ContainerizationEXT4/EXT4+FileTree.swift b/Sources/ContainerizationEXT4/EXT4+FileTree.swift index 8cbc5d154..427e599c7 100644 --- a/Sources/ContainerizationEXT4/EXT4+FileTree.swift +++ b/Sources/ContainerizationEXT4/EXT4+FileTree.swift @@ -62,13 +62,7 @@ extension EXT4 { _ptr = ptr.pointee.parent } let path = components.reversed().joined(separator: "/") - guard let data = path.data(using: .utf8) else { - return nil - } - guard let dataPath = String(data: data, encoding: .utf8) else { - return nil - } - return FilePath(dataPath).lexicallyNormalized() + return FilePath(path).lexicallyNormalized() } }