Skip to content

Commit

Permalink
Wait to create parent directory before linking
Browse files Browse the repository at this point in the history
  • Loading branch information
saagarjha committed May 27, 2022
1 parent fe7e59e commit ab0ccc3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions unxip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ struct Main {

// The assumption is that all directories are provided without trailing slashes
func parentDirectory<S: StringProtocol>(of path: S) -> S.SubSequence {
return path[..<path.lastIndex(of: "/")!]
path[..<path.lastIndex(of: "/")!]
}

// https://bugs.swift.org/browse/SR-15816
Expand All @@ -435,9 +435,11 @@ struct Main {
continue
}

if let (original, task) = hardlinks[file.identifier] {
if let (original, originalTask) = hardlinks[file.identifier] {
let task = parentDirectoryTask(for: file)
assert(task != nil, file.name)
_ = taskStream.addRunningTask {
await task.value
_ = await (originalTask.value, task?.value)
warn(link(original, file.name), "linking")
}
continue
Expand All @@ -450,6 +452,7 @@ struct Main {
let task = parentDirectoryTask(for: file)
assert(task != nil, file.name)
_ = taskStream.addRunningTask {
await task?.value
warn(symlink(String(data: Data(file.data.map(Array.init).reduce([], +)), encoding: .utf8), file.name), "symlinking")
setStickyBit(on: file)
}
Expand Down

0 comments on commit ab0ccc3

Please sign in to comment.