Skip to content

Commit 0c35386

Browse files
authored
Issue 17 (#18)
* update version * add defer close for dst file descriptor for non-atomic copy
1 parent 17f336f commit 0c35386

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.1.4
1+
v0.1.5

copy.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ type File struct {
3030

3131
// NewFile creates a new File.
3232
func NewFile(path string) *File {
33-
return &File{
34-
Path: path,
35-
}
33+
return &File{Path: path}
3634
}
3735

3836
// setInfo will collect information about a File and populate the necessary fields.
@@ -278,6 +276,11 @@ func copyFile(srcFile, dstFile *File, opts Options) (err error) {
278276
if err != nil {
279277
return errors.Wrapf(ErrCannotOpenOrCreateDstFile, "destination file %s: %s", dstFile.Path, err)
280278
}
279+
defer func() {
280+
if closeErr := dstFD.Close(); closeErr != nil {
281+
err = closeErr
282+
}
283+
}()
281284

282285
opts.logInfo("copying src file %s to dst file %s", srcFD.Name(), dstFD.Name())
283286
if _, err = io.Copy(dstFD, srcFD); err != nil {

option.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type Options struct {
2828
// NoClobber will not let an existing file be overwritten.
2929
NoClobber bool
3030
// Parents will create source directories in dst if they do not already exist. ErrWithParentsDstMustBeDir
31-
// is returned is destination is not a directory.
31+
// is returned if destination is not a directory.
3232
Parents bool
3333
// Recursive will recurse through sub directories if set true.
3434
Recursive bool

0 commit comments

Comments
 (0)