Skip to content

Commit

Permalink
do not remove but truncate file to overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed Jul 25, 2024
1 parent 2c096ee commit 0889140
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
40 changes: 24 additions & 16 deletions fs/fs_bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,12 @@ func (fs *FileSystem) UploadFile(localPath string, irodsPath string, resource st
} else {
switch entry.Type {
case FileEntry:
// delete first to prevent stale data
err = fs.RemoveFile(irodsDestPath, true)
if err != nil {
return fileTransferResult, xerrors.Errorf("failed to delete data object %s for overwrite: %w", irodsDestPath, err)
// truncate first to prevent stale data
if entry.Size > 0 {
err = fs.TruncateFile(irodsDestPath, 0)
if err != nil {
return fileTransferResult, xerrors.Errorf("failed to truncate data object %s for overwrite: %w", irodsDestPath, err)
}
}
case DirectoryEntry:
localFileName := filepath.Base(localSrcPath)
Expand Down Expand Up @@ -623,10 +625,12 @@ func (fs *FileSystem) UploadFileFromBuffer(buffer bytes.Buffer, irodsPath string
} else {
switch entry.Type {
case FileEntry:
// delete first to prevent stale data
err = fs.RemoveFile(irodsDestPath, true)
if err != nil {
return fileTransferResult, xerrors.Errorf("failed to delete data object %s for overwrite: %w", irodsDestPath, err)
// truncate first to prevent stale data
if entry.Size > 0 {
err = fs.TruncateFile(irodsDestPath, 0)
if err != nil {
return fileTransferResult, xerrors.Errorf("failed to truncate data object %s for overwrite: %w", irodsDestPath, err)
}
}
case DirectoryEntry:
return fileTransferResult, xerrors.Errorf("invalid entry type %s. Destination must be a file", entry.Type)
Expand Down Expand Up @@ -714,10 +718,12 @@ func (fs *FileSystem) UploadFileParallel(localPath string, irodsPath string, res
} else {
switch entry.Type {
case FileEntry:
// delete first to prevent stale data
err = fs.RemoveFile(irodsDestPath, true)
if err != nil {
return fileTransferResult, xerrors.Errorf("failed to delete data object %s for overwrite: %w", irodsDestPath, err)
// truncate first to prevent stale data
if entry.Size > 0 {
err = fs.TruncateFile(irodsDestPath, 0)
if err != nil {
return fileTransferResult, xerrors.Errorf("failed to truncate data object %s for overwrite: %w", irodsDestPath, err)
}
}
case DirectoryEntry:
localFileName := filepath.Base(localSrcPath)
Expand Down Expand Up @@ -806,10 +812,12 @@ func (fs *FileSystem) UploadFileParallelRedirectToResource(localPath string, iro
} else {
switch entry.Type {
case FileEntry:
// delete first to prevent stale data
err = fs.RemoveFile(irodsDestPath, true)
if err != nil {
return fileTransferResult, xerrors.Errorf("failed to delete data object %s for overwrite: %w", irodsDestPath, err)
// truncate first to prevent stale data
if entry.Size > 0 {
err = fs.TruncateFile(irodsDestPath, 0)
if err != nil {
return fileTransferResult, xerrors.Errorf("failed to truncate data object %s for overwrite: %w", irodsDestPath, err)
}
}
case DirectoryEntry:
localFileName := filepath.Base(localSrcPath)
Expand Down
1 change: 1 addition & 0 deletions irods/types/object_type.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package types

// ObjectType determines if the object is data object or collection in irods
type ObjectType string

const (
Expand Down

0 comments on commit 0889140

Please sign in to comment.