diff --git a/Sources/Shared/Toolkit/Archive/ExplodedArchive.swift b/Sources/Shared/Toolkit/Archive/ExplodedArchive.swift index b3e1226b9..c9f25bb44 100644 --- a/Sources/Shared/Toolkit/Archive/ExplodedArchive.swift +++ b/Sources/Shared/Toolkit/Archive/ExplodedArchive.swift @@ -23,7 +23,7 @@ final class ExplodedArchive: Archive, Loggable { } private init(file: FileURL) { - root = file + root = file.resolvingSymlinks() } lazy var entries: [ArchiveEntry] = { @@ -52,7 +52,6 @@ final class ExplodedArchive: Archive, Loggable { private func makeEntry(at url: FileURL) -> ArchiveEntry? { guard - root.isParent(of: url), let values = try? url.url.resourceValues(forKeys: [.fileSizeKey, .isDirectoryKey]), let length = values.fileSize, values.isDirectory != true @@ -68,7 +67,7 @@ final class ExplodedArchive: Archive, Loggable { } private func entryURL(fromPath path: String) -> FileURL? { - let url = root.appendingPath(path, isDirectory: false) + let url = root.appendingPath(path, isDirectory: false).resolvingSymlinks() guard root.isParent(of: url) else { diff --git a/Sources/Shared/Toolkit/URL/Absolute URL/FileURL.swift b/Sources/Shared/Toolkit/URL/Absolute URL/FileURL.swift index 979d4e794..8531192de 100644 --- a/Sources/Shared/Toolkit/URL/Absolute URL/FileURL.swift +++ b/Sources/Shared/Toolkit/URL/Absolute URL/FileURL.swift @@ -44,6 +44,12 @@ public struct FileURL: AbsoluteURL, Hashable { url.lastPathComponent } + /// Returns new `FileURL` with symlinks resolved + // FIXME: Async + public func resolvingSymlinks() -> Self { + Self(url: url.resolvingSymlinksInPath())! + } + /// Returns whether the given `url` is `self` or one of its descendants. public func isParent(of other: FileURL) -> Bool { path == other.path || other.path.hasPrefix(path.addingSuffix("/"))