File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -755,3 +755,34 @@ public struct RerootedFileSystemView: FileSystem {
755
755
756
756
/// Public access to the local FS proxy.
757
757
public var localFileSystem : FileSystem = LocalFileSystem ( )
758
+
759
+ extension FileSystem {
760
+ /// Print the filesystem tree of the given path.
761
+ ///
762
+ /// For debugging only.
763
+ public func dumpTree( at path: AbsolutePath = . root) {
764
+ print ( " . " )
765
+ do {
766
+ try recurse ( fs: self , path: path)
767
+ } catch {
768
+ print ( " \( error) " )
769
+ }
770
+ }
771
+
772
+ /// Helper method to recurse and print the tree.
773
+ private func recurse( fs: FileSystem , path: AbsolutePath , prefix: String = " " ) throws {
774
+ let contents = try fs. getDirectoryContents ( path)
775
+
776
+ for (idx, entry) in contents. enumerated ( ) {
777
+ let isLast = idx == contents. count - 1
778
+ let line = prefix + ( isLast ? " └── " : " ├── " ) + entry
779
+ print ( line)
780
+
781
+ let entryPath = path. appending ( component: entry)
782
+ if fs. isDirectory ( entryPath) {
783
+ let childPrefix = prefix + ( isLast ? " " : " │ " )
784
+ try recurse ( fs: fs, path: entryPath, prefix: String ( childPrefix) )
785
+ }
786
+ }
787
+ }
788
+ }
You can’t perform that action at this time.
0 commit comments