Skip to content

Commit

Permalink
copier: RemoveAll possibly-directories
Browse files Browse the repository at this point in the history
When we attempt to remove a directory to make way for a non-directory as
part of extracting content, use RemoveAll() instead of Remove().

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
  • Loading branch information
nalind committed Jan 24, 2022
1 parent 9091023 commit 4a83110
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions copier/copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ func copierHandlerPut(bulkReader io.Reader, req request, idMappings *idtools.IDM
break
}
}
if err = os.Remove(path); err == nil {
if err = os.RemoveAll(path); err == nil {
err = os.Link(linkTarget, path)
}
}
Expand All @@ -1696,7 +1696,7 @@ func copierHandlerPut(bulkReader io.Reader, req request, idMappings *idtools.IDM
break
}
}
if err = os.Remove(path); err == nil {
if err = os.RemoveAll(path); err == nil {
err = os.Symlink(filepath.FromSlash(hdr.Linkname), filepath.FromSlash(path))
}
}
Expand All @@ -1711,7 +1711,7 @@ func copierHandlerPut(bulkReader io.Reader, req request, idMappings *idtools.IDM
break
}
}
if err = os.Remove(path); err == nil {
if err = os.RemoveAll(path); err == nil {
err = mknod(path, chrMode(0600), int(mkdev(devMajor, devMinor)))
}
}
Expand All @@ -1726,7 +1726,7 @@ func copierHandlerPut(bulkReader io.Reader, req request, idMappings *idtools.IDM
break
}
}
if err = os.Remove(path); err == nil {
if err = os.RemoveAll(path); err == nil {
err = mknod(path, blkMode(0600), int(mkdev(devMajor, devMinor)))
}
}
Expand Down Expand Up @@ -1758,7 +1758,7 @@ func copierHandlerPut(bulkReader io.Reader, req request, idMappings *idtools.IDM
break
}
}
if err = os.Remove(path); err == nil {
if err = os.RemoveAll(path); err == nil {
err = mkfifo(path, 0600)
}
}
Expand Down
1 change: 1 addition & 0 deletions copier/copier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ func testPut(t *testing.T) {
{Name: "target", Typeflag: tar.TypeSymlink, Mode: 0755, Linkname: "target", ModTime: testDate},
{Name: "target", Typeflag: tar.TypeReg, Size: 123, Mode: 0755, ModTime: testDate},
{Name: "test", Typeflag: tar.TypeDir, Size: 0, Mode: 0755, ModTime: testDate},
{Name: "test/content", Typeflag: tar.TypeReg, Size: 0, Mode: 0755, ModTime: testDate},
{Name: "test", Typeflag: typeFlag, Size: 0, Mode: 0755, Linkname: "target", ModTime: testDate},
})
tmp, err := ioutil.TempDir("", "copier-test-")
Expand Down

0 comments on commit 4a83110

Please sign in to comment.