fix issue in failed installing when there's shortcut between file paths for command install (#2326)

* fix issue in failed installing when has shortcut between file paths for command install

* version updates

* template for command gf updates
This commit is contained in:
John Guo
2022-11-25 10:34:00 +08:00
committed by GitHub
parent 0a76b9c61b
commit ef7fec7e24
5 changed files with 14 additions and 20 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -119,20 +119,13 @@ func (s serviceInstall) Run(ctx context.Context) (err error) {
dstPath := paths[selectedID]
// Install the new binary.
mlog.Debugf(`copy file from "%s" to "%s"`, gfile.SelfPath(), dstPath.filePath)
err = gfile.CopyFile(gfile.SelfPath(), dstPath.filePath)
if err != nil {
mlog.Printf("install gf binary to '%s' failed: %v", dstPath.dirPath, err)
mlog.Printf("you can manually install gf by copying the binary to folder: %s", dstPath.dirPath)
} else {
mlog.Printf("gf binary is successfully installed to: %s", dstPath.dirPath)
}
// Uninstall the old binary.
for _, path := range paths {
// Do not delete myself.
if path.filePath != "" && path.filePath != dstPath.filePath && gfile.SelfPath() != path.filePath {
_ = gfile.Remove(path.filePath)
}
mlog.Printf("gf binary is successfully installed to: %s", dstPath.filePath)
}
return
}

View File

@ -50,34 +50,35 @@ func CopyFile(src, dst string) (err error) {
if src == dst {
return nil
}
in, err := Open(src)
var inFile *os.File
inFile, err = Open(src)
if err != nil {
return
}
defer func() {
if e := in.Close(); e != nil {
if e := inFile.Close(); e != nil {
err = gerror.Wrapf(e, `file close failed for "%s"`, src)
}
}()
out, err := Create(dst)
var outFile *os.File
outFile, err = Create(dst)
if err != nil {
return
}
defer func() {
if e := out.Close(); e != nil {
if e := outFile.Close(); e != nil {
err = gerror.Wrapf(e, `file close failed for "%s"`, dst)
}
}()
if _, err = io.Copy(out, in); err != nil {
if _, err = io.Copy(outFile, inFile); err != nil {
err = gerror.Wrapf(err, `io.Copy failed from "%s" to "%s"`, src, dst)
return
}
if err = out.Sync(); err != nil {
if err = outFile.Sync(); err != nil {
err = gerror.Wrapf(err, `file sync failed for file "%s"`, dst)
return
}
err = Chmod(dst, DefaultPermCopy)
if err != nil {
if err = Chmod(dst, DefaultPermCopy); err != nil {
return
}
return

View File

@ -2,5 +2,5 @@ package gf
const (
// VERSION is the current GoFrame version.
VERSION = "v2.2.4"
VERSION = "v2.2.5"
)