Skip to content

Commit

Permalink
fixed issue #17
Browse files Browse the repository at this point in the history
- raised file put warning if the file at local is a symlink
- used the file size of the symlink target for size mismatch check
  • Loading branch information
hurngchunlee committed Nov 22, 2023
1 parent 88a039b commit 3c9a297
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions internal/cmd/repocli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

dav "github.com/studio-b12/gowebdav"

"github.com/Donders-Institute/tg-toolset-golang/pkg/logger"
log "github.com/Donders-Institute/tg-toolset-golang/pkg/logger"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -1421,6 +1422,11 @@ func putRepoFile(pfinfoLocal, pfinfoRepo pathFileInfo, showProgress bool) error
}
defer reader.Close()

// print a warning if the file is a symbolic link
if pfinfoLocal.info.Mode()&fs.ModeSymlink != 0 {
logger.Warnf("%s is a symbolic link", pfinfoLocal.path)
}

// read pathRepo and write to pathLocal, the mode is not actually useful (!?)
err = cli.WriteStream(pfinfoRepo.path, reader, pfinfoLocal.info.Mode())
if err != nil {
Expand All @@ -1433,8 +1439,16 @@ func putRepoFile(pfinfoLocal, pfinfoRepo pathFileInfo, showProgress bool) error
return fmt.Errorf("cannot stat %s at the repository: %s", pfinfoRepo.path, err)
}

if f.Size() != pfinfoLocal.info.Size() {
return fmt.Errorf("file size %s mis-match: %d != %d", pfinfoRepo.path, f.Size(), pfinfoLocal.info.Size())
// get actual file size if pfinfoLocal.info.Mode() == fs.ModeSymlink
lsize := pfinfoLocal.info.Size()
if pfinfoLocal.info.Mode()&fs.ModeSymlink != 0 {
if tinfo, err := os.Stat(pfinfoLocal.path); err == nil {
lsize = tinfo.Size()
}
}

if f.Size() != lsize {
return fmt.Errorf("file size %s mis-match: %d != %d", pfinfoRepo.path, f.Size(), lsize)
}

// TODO: this jumps from 0% to 100% ... not ideal but there is no way with to get upload progression with the webdav client library
Expand Down

0 comments on commit 3c9a297

Please sign in to comment.