0

Upgrade versions of vendored libs

This commit is contained in:
eleksir
2023-05-18 23:55:10 +03:00
parent 4869c146fe
commit 7958db9c0d
555 changed files with 36170 additions and 15565 deletions

View File

@@ -12,8 +12,9 @@ import (
)
type cloneOpts struct {
skip func(string) bool
sync bool
skip func(string) bool
sync bool
tryLink bool
}
// A CloneOption configures the behavior of Clone.
@@ -28,6 +29,12 @@ func CloneSkip(fn func(string) bool) CloneOption {
// CloneSync configures Clone to sync files and directories.
var CloneSync CloneOption = func(o *cloneOpts) { o.sync = true }
// CloneTryLink configures Clone to link files to the destination if the source and
// destination filesystems are the same. If the source and destination
// filesystems are not the same or the filesystem does not support linking, then
// Clone falls back to copying.
var CloneTryLink CloneOption = func(o *cloneOpts) { o.tryLink = true }
// Clone recursively copies a directory structure from srcFS to dstFS. srcPath
// specifies the path in srcFS to copy from and must be compatible with the
// srcFS path format. dstDir is the target directory in dstFS and must be
@@ -49,6 +56,7 @@ func Clone(srcFS, dstFS FS, srcPath, dstPath string, opts ...CloneOption) (bool,
}
return false, err
}
defer srcFile.Close()
stat, err := srcFile.Stat()
if err != nil {
@@ -56,9 +64,6 @@ func Clone(srcFS, dstFS FS, srcPath, dstPath string, opts ...CloneOption) (bool,
}
if stat.IsDir() {
if err := srcFile.Close(); err != nil {
return false, err
}
if err := dstFS.MkdirAll(dstPath, 0755); err != nil {
return false, err
}
@@ -94,13 +99,25 @@ func Clone(srcFS, dstFS FS, srcPath, dstPath string, opts ...CloneOption) (bool,
return true, nil
}
// If the source and destination filesystems are the same and the user
// specified they'd prefer to link if possible, try to use a hardlink,
// falling back to copying if it fails.
if srcFS == dstFS && o.tryLink {
if err := LinkOrCopy(srcFS, srcPath, dstPath); oserror.IsNotExist(err) {
// Clone's semantics are such that it returns (false,nil) if the
// source does not exist.
return false, nil
} else if err != nil {
return false, err
} else {
return true, nil
}
}
data, err := io.ReadAll(srcFile)
if err != nil {
return false, err
}
if err := srcFile.Close(); err != nil {
return false, err
}
dstFile, err := dstFS.Create(dstPath)
if err != nil {
return false, err
@@ -113,7 +130,6 @@ func Clone(srcFS, dstFS FS, srcPath, dstPath string, opts ...CloneOption) (bool,
return false, err
}
}
if err := dstFile.Close(); err != nil {
return false, err
}