Skip to content

Commit

Permalink
Handle URLs with aliases in ExplodedArchive
Browse files Browse the repository at this point in the history
  • Loading branch information
domkm committed May 28, 2024
1 parent 434e47b commit cc6c1fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Sources/Shared/Toolkit/Archive/ExplodedArchive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class ExplodedArchive: Archive, Loggable {
}

private init(file: FileURL) {
root = file
root = file.resolvingSymlinks()
}

lazy var entries: [ArchiveEntry] = {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions Sources/Shared/Toolkit/URL/Absolute URL/FileURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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("/"))
Expand Down

0 comments on commit cc6c1fa

Please sign in to comment.