Skip to content

Commit

Permalink
do not try to delete a data object when ticket is used
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed Jan 21, 2025
1 parent 54e6a34 commit b1bce87
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 12 deletions.
5 changes: 5 additions & 0 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ func (fs *FileSystem) SupportParallelUpload() bool {
return fs.metadataSession.SupportParallelUpload()
}

// IsTicketAccess returns if the access is authenticated using ticket
func (fs *FileSystem) IsTicketAccess() bool {
return fs.account.UseTicket()
}

// GetMetrics returns metrics
func (fs *FileSystem) GetMetrics() *metrics.IRODSMetrics {
ioMetrics := fs.ioSession.GetMetrics()
Expand Down
60 changes: 48 additions & 12 deletions fs/fs_bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,18 @@ func (fs *FileSystem) UploadFile(localPath string, irodsPath string, resource st
localFileName := filepath.Base(localSrcPath)
irodsFilePath = util.MakeIRODSPath(irodsDestPath, localFileName)
} else {
err = fs.RemoveFile(irodsDestPath, true)
if err != nil {
return fileTransferResult, xerrors.Errorf("failed to remove data object %q for overwrite: %w", irodsDestPath, err)
if fs.IsTicketAccess() {
// ticket does not support removing a file
if stat.Size() < entry.Size {
return fileTransferResult, xerrors.Errorf("failed to overwrite a file %q with a smaller file", irodsDestPath)
}

// try to overwrite the file
} else {
err = fs.RemoveFile(irodsDestPath, true)
if err != nil {
return fileTransferResult, xerrors.Errorf("failed to remove data object %q for overwrite: %w", irodsDestPath, err)
}
}
}
}
Expand Down Expand Up @@ -644,9 +653,18 @@ func (fs *FileSystem) UploadFileFromBuffer(buffer *bytes.Buffer, irodsPath strin
if entry.IsDir() {
return fileTransferResult, xerrors.Errorf("invalid entry type %q. Destination must be a file", entry.Type)
} else {
err = fs.RemoveFile(irodsDestPath, true)
if err != nil {
return fileTransferResult, xerrors.Errorf("failed to remove data object %q for overwrite: %w", irodsDestPath, err)
if fs.IsTicketAccess() {
// ticket does not support removing a file
if int64(buffer.Len()) < entry.Size {
return fileTransferResult, xerrors.Errorf("failed to overwrite a file %q with a smaller file", irodsDestPath)
}

// try to overwrite the file
} else {
err = fs.RemoveFile(irodsDestPath, true)
if err != nil {
return fileTransferResult, xerrors.Errorf("failed to remove data object %q for overwrite: %w", irodsDestPath, err)
}
}
}
}
Expand Down Expand Up @@ -750,9 +768,18 @@ func (fs *FileSystem) UploadFileParallel(localPath string, irodsPath string, res
localFileName := filepath.Base(localSrcPath)
irodsFilePath = util.MakeIRODSPath(irodsDestPath, localFileName)
} else {
err = fs.RemoveFile(irodsDestPath, true)
if err != nil {
return fileTransferResult, xerrors.Errorf("failed to remove data object %q for overwrite: %w", irodsDestPath, err)
if fs.IsTicketAccess() {
// ticket does not support removing a file
if stat.Size() < entry.Size {
return fileTransferResult, xerrors.Errorf("failed to overwrite a file %q with a smaller file", irodsDestPath)
}

// try to overwrite the file
} else {
err = fs.RemoveFile(irodsDestPath, true)
if err != nil {
return fileTransferResult, xerrors.Errorf("failed to remove data object %q for overwrite: %w", irodsDestPath, err)
}
}
}
}
Expand Down Expand Up @@ -856,9 +883,18 @@ func (fs *FileSystem) UploadFileParallelRedirectToResource(localPath string, iro
localFileName := filepath.Base(localSrcPath)
irodsFilePath = util.MakeIRODSPath(irodsDestPath, localFileName)
} else {
err = fs.RemoveFile(irodsDestPath, true)
if err != nil {
return fileTransferResult, xerrors.Errorf("failed to remove data object %q for overwrite: %w", irodsDestPath, err)
if fs.IsTicketAccess() {
// ticket does not support removing a file
if stat.Size() < entry.Size {
return fileTransferResult, xerrors.Errorf("failed to overwrite a file %q with a smaller file", irodsDestPath)
}

// try to overwrite the file
} else {
err = fs.RemoveFile(irodsDestPath, true)
if err != nil {
return fileTransferResult, xerrors.Errorf("failed to remove data object %q for overwrite: %w", irodsDestPath, err)
}
}
}
}
Expand Down

0 comments on commit b1bce87

Please sign in to comment.