go: remove redefinitions of builtins

Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
Paul Meyer 2023-03-20 11:08:46 +01:00
parent 6c4ebe12f3
commit bad05321a0
2 changed files with 5 additions and 5 deletions

View File

@ -34,7 +34,7 @@ func teardown(devicePath string) {
_ = exec.Command("/bin/rm", "-f", devicePath).Run()
}
func copy(source, target string) error {
func cp(source, target string) error {
return exec.Command("cp", source, target).Run()
}
@ -142,7 +142,7 @@ func TestDeviceCloning(t *testing.T) {
_, err := mapper.OpenCryptDevice(context.Background(), DevicePath, DeviceName, false)
assert.NoError(err)
require.NoError(copy(DevicePath, DevicePath+"-copy"))
require.NoError(cp(DevicePath, DevicePath+"-copy"))
defer teardown(DevicePath + "-copy")
_, err = mapper.OpenCryptDevice(context.Background(), DevicePath+"-copy", DeviceName+"-copy", false)

View File

@ -223,17 +223,17 @@ func (i *OsInstaller) copy(oldname, newname string, perm fs.FileMode) (err error
if err := i.fs.MkdirAll(path.Dir(newname), fs.ModePerm); err != nil {
return fmt.Errorf("copying %q to %q: unable to create destination folder: %w", oldname, newname, err)
}
new, openNewErr := i.fs.OpenFile(newname, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, perm)
newFile, openNewErr := i.fs.OpenFile(newname, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, perm)
if openNewErr != nil {
return fmt.Errorf("copying %q to %q: cannot open destination file for writing: %w", oldname, newname, openNewErr)
}
defer func() {
_ = new.Close()
_ = newFile.Close()
if err != nil {
_ = i.fs.Remove(newname)
}
}()
if _, err := io.Copy(new, old); err != nil {
if _, err := io.Copy(newFile, old); err != nil {
return fmt.Errorf("copying %q to %q: copying file contents: %w", oldname, newname, err)
}