Add 'copy-file' command. #104220
No reviewers
Labels
No Label
Good First Issue
Priority
High
Priority
Low
Priority
Normal
Status
Archived
Status
Confirmed
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: studio/flamenco#104220
Loading…
Reference in New Issue
No description provided.
Delete Branch "mont29/flamenco:file-management-experiments"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Initial implementation with some basic tests.
The API command only accept one source and destination path, which must
be absolute. If the destination already exists, it will not be
ovewritten, and an error is generated.
JS job definition code using this new command can easily handle list of
paths and/or relative paths if needed.
Thanks for the PR! I've included a few notes on how the code could be simplified.
On Windows the unit test fails, so it's good that you wrote it because I overlooked a little bug as well ;-)
Testing is relatively easy if you have Wine installed:
This fails because it feels that
C:\blablabla
is not an absolute path. The issue is the use ofpath.IsAbs()
, as thepath
module is for POSIX/URL-style paths only. usefilepath.IsAbs()
instead, as that takes care of OS-specific file paths.@ -83,0 +86,4 @@
// It takes an absolute source and destination file path,
// and copies the source file to its destination, if possible.
// Missing directories in destination path are created as needed.
// If the target path already exists, nothing happens. Destination will not be overwritten.
This comment implies that there also won't be any error returned, which is inconsistent with the PR description.
@ -83,0 +87,4 @@
// and copies the source file to its destination, if possible.
// Missing directories in destination path are created as needed.
// If the target path already exists, nothing happens. Destination will not be overwritten.
func (ce *CommandExecutor) cmdCopyFile(ctx context.Context, logger zerolog.Logger, taskID string, cmd api.Command) error {
I think it might clean up the code a bit if the file copying logic was decoupled from the error logging. I'm thinking about something like this:
@ -99,6 +161,73 @@ func (ce *CommandExecutor) moveAndLog(ctx context.Context, taskID, cmdName, src,
return nil
}
func (ce *CommandExecutor) fileCopyAndLog(ctx context.Context, taskID, cmdName, src, dest string) error {
With the above refactor, I think this function would not need to be part of
CommandExecutor
any more, and become a standalone function to copy files.@ -102,0 +187,4 @@
}
if !src_file_stat.Mode().IsRegular() {
err := fmt.Errorf("Not a regular file")
Either wrap an existing error type, or declare an error variable that can be tested against. That way the calling code can distinguish this error from others. When there's no formatting done, use
errors.New(...)
to create the error.And I think the error object creation can be done later, to avoid overlapping scopes:
Thanks, indeed simplifies the error handling.
Not very happy with the naming of the functions now though,
cmdCopyFile
callingcopyFile
callingfileCopy
... :/Maybe
cmdCopyFile
->checkAndCopyFile
->fileCopy
?Maybe the cmd parameter checks could be moved into
cmdCopyFile
, then we can get rid of the intermediate function.Good point!
Since the whole logic handling logging messages and errors is the same and relatively verbose, think it makes sense to isolate it into its own utils.
NOTE: new
errorLogProcess
could also be used for other commands, likecmdMoveDirectory
, in a future cleanup.Much improved, thanks!