Skip to content

Commit feb27a3

Browse files
committed
Try to fix hardlink failures.
1 parent a45a00f commit feb27a3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

internal/unarchiver/unarchiver.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ func writeNewHardLink(fpath string, target string) error {
132132
return fmt.Errorf("%s: making directory for file: %v", fpath, err)
133133
}
134134

135+
// The unarchiving process is unordered, and a hardlinked file's target may not yet exist.
136+
// Create it. writeNewFile() will overwrite it later, which is okay.
137+
if !fileExists(target) {
138+
err = os.MkdirAll(filepath.Dir(target), 0755)
139+
if err != nil {
140+
return fmt.Errorf("%s: making directory for file: %v", target, err)
141+
}
142+
f, err := os.Create(target)
143+
if err != nil {
144+
return fmt.Errorf("%s: creating target file: %v", target, err)
145+
}
146+
f.Close()
147+
}
148+
135149
err = os.Link(target, fpath)
136150
if err != nil {
137151
return fmt.Errorf("%s: making hard link for: %v", fpath, err)

0 commit comments

Comments
 (0)