Skip to content

Commit

Permalink
Fix bput bug in setting staging dir
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed Sep 4, 2024
1 parent 2fb5285 commit 52c3a4d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
8 changes: 4 additions & 4 deletions cmd/subcmd/bput.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,19 @@ func (bput *BputCommand) Process() error {
}

// bundle root path
bundleRootPath := "/"
bundleRootPath, err = commons.GetCommonRootLocalDirPath(bput.sourcePaths)
localBundleRootPath := string(filepath.Separator)
localBundleRootPath, err = commons.GetCommonRootLocalDirPath(bput.sourcePaths)
if err != nil {
return xerrors.Errorf("failed to get a common root directory for source paths: %w", err)
}

if !bput.noRootFlagValues.NoRoot {
// use parent dir
bundleRootPath = filepath.Dir(bundleRootPath)
localBundleRootPath = filepath.Dir(localBundleRootPath)
}

// bundle transfer manager
bput.bundleTransferManager = commons.NewBundleTransferManager(bput.filesystem, bput.transferReportManager, bput.targetPath, bundleRootPath, bput.bundleTransferFlagValues.MinFileNum, bput.bundleTransferFlagValues.MaxFileNum, bput.bundleTransferFlagValues.MaxFileSize, bput.parallelTransferFlagValues.SingleThread, bput.parallelTransferFlagValues.ThreadNumber, bput.parallelTransferFlagValues.RedirectToResource, bput.parallelTransferFlagValues.Icat, bput.bundleTransferFlagValues.LocalTempPath, bput.bundleTransferFlagValues.IRODSTempPath, bput.bundleTransferFlagValues.NoBulkRegistration, bput.progressFlagValues.ShowProgress, bput.progressFlagValues.ShowFullPath)
bput.bundleTransferManager = commons.NewBundleTransferManager(bput.filesystem, bput.transferReportManager, bput.targetPath, localBundleRootPath, bput.bundleTransferFlagValues.MinFileNum, bput.bundleTransferFlagValues.MaxFileNum, bput.bundleTransferFlagValues.MaxFileSize, bput.parallelTransferFlagValues.SingleThread, bput.parallelTransferFlagValues.ThreadNumber, bput.parallelTransferFlagValues.RedirectToResource, bput.parallelTransferFlagValues.Icat, bput.bundleTransferFlagValues.LocalTempPath, stagingDirPath, bput.bundleTransferFlagValues.NoBulkRegistration, bput.progressFlagValues.ShowProgress, bput.progressFlagValues.ShowFullPath)
bput.bundleTransferManager.Start()

// run
Expand Down
25 changes: 18 additions & 7 deletions commons/bundle_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,24 @@ func (bundle *Bundle) Add(sourceStat fs.FileInfo, sourcePath string) error {
}

func (bundle *Bundle) updateBundlePath() error {
logger := log.WithFields(log.Fields{
"package": "commons",
"struct": "BundleTransferManager",
"function": "updateBundlePath",
})

filename, err := bundle.GetBundleFilename()
if err != nil {
return xerrors.Errorf("failed to get bundle filename: %w", err)
}

logger.Debugf("bundle local temp path %q, irods temp path %q", bundle.manager.localTempDirPath, bundle.manager.irodsTempDirPath)

bundle.LocalBundlePath = filepath.Join(bundle.manager.localTempDirPath, filename)
bundle.IRODSBundlePath = filepath.Join(bundle.manager.irodsTempDirPath, filename)
bundle.IRODSBundlePath = path.Join(bundle.manager.irodsTempDirPath, filename)

logger.Debugf("bundle local path %q, irods path %q", bundle.LocalBundlePath, bundle.IRODSBundlePath)

return nil
}

Expand All @@ -160,7 +171,7 @@ type BundleTransferManager struct {
nextBundleIndex int64
pendingBundles chan *Bundle
bundles []*Bundle
bundleRootPath string
localBundleRootPath string
minBundleFileNum int
maxBundleFileNum int
maxBundleFileSize int64
Expand All @@ -187,7 +198,7 @@ type BundleTransferManager struct {
}

// NewBundleTransferManager creates a new BundleTransferManager
func NewBundleTransferManager(fs *irodsclient_fs.FileSystem, transferReportManager *TransferReportManager, irodsDestPath string, bundleRootPath string, minBundleFileNum int, maxBundleFileNum int, maxBundleFileSize int64, singleThreaded bool, uploadThreadNum int, redirectToResource bool, useIcat bool, localTempDirPath string, irodsTempDirPath string, noBulkReg bool, showProgress bool, showFullPath bool) *BundleTransferManager {
func NewBundleTransferManager(fs *irodsclient_fs.FileSystem, transferReportManager *TransferReportManager, irodsDestPath string, localBundleRootPath string, minBundleFileNum int, maxBundleFileNum int, maxBundleFileSize int64, singleThreaded bool, uploadThreadNum int, redirectToResource bool, useIcat bool, localTempDirPath string, irodsTempDirPath string, noBulkReg bool, showProgress bool, showFullPath bool) *BundleTransferManager {
cwd := GetCWD()
home := GetHomeDir()
zone := GetZone()
Expand All @@ -201,7 +212,7 @@ func NewBundleTransferManager(fs *irodsclient_fs.FileSystem, transferReportManag
nextBundleIndex: 0,
pendingBundles: make(chan *Bundle, 100),
bundles: []*Bundle{},
bundleRootPath: "/",
localBundleRootPath: localBundleRootPath,
minBundleFileNum: minBundleFileNum,
maxBundleFileNum: maxBundleFileNum,
maxBundleFileSize: maxBundleFileSize,
Expand Down Expand Up @@ -260,9 +271,9 @@ func (manager *BundleTransferManager) progress(name string, processed int64, tot
}

func (manager *BundleTransferManager) GetTargetPath(localPath string) (string, error) {
relPath, err := filepath.Rel(manager.bundleRootPath, localPath)
relPath, err := filepath.Rel(manager.localBundleRootPath, localPath)
if err != nil {
return "", xerrors.Errorf("failed to compute relative path %q to %q: %w", localPath, manager.bundleRootPath, err)
return "", xerrors.Errorf("failed to compute relative path %q to %q: %w", localPath, manager.localBundleRootPath, err)
}

return path.Join(manager.irodsDestPath, filepath.ToSlash(relPath)), nil
Expand Down Expand Up @@ -841,7 +852,7 @@ func (manager *BundleTransferManager) processBundleTar(bundle *Bundle) error {
entries[idx] = entry.LocalPath
}

err := Tar(manager.bundleRootPath, entries, bundle.LocalBundlePath, callbackTar)
err := Tar(manager.localBundleRootPath, entries, bundle.LocalBundlePath, callbackTar)
if err != nil {
manager.progress(progressName, 0, totalFileNum, progress.UnitsDefault, true)
return xerrors.Errorf("failed to create a tarball for bundle %d to %q: %w", bundle.Index, bundle.LocalBundlePath, err)
Expand Down

0 comments on commit 52c3a4d

Please sign in to comment.