Skip to content

Commit

Permalink
Added documentation and merged 2 if statments.
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverLok committed Dec 3, 2024
1 parent 6f93ccd commit e0a2c0b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion docs/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,9 @@ All types of FileSpecs share some common fields:

A FileSpec with `type` equal to `path` points to an absolute or relative path accessible from the current machine.
The path may also include a glob pattern to target multiple files or directories.
For paths that match multiple dirents, the dirents will be copied into `dest`.
For paths that match multiple dirents, the dirents will be copied into `dest` only if `dest` is a directory.
If `dest` does not exist, it will be automatically created as a directory.
Attempting to copy multiple dirents into `dest` if `dest` is an existing file will result in an error.
When a relative path is specified, additional context is required to know the relative base.
For example, a FileSpec in an assignment config is relative to the assignment directory (the directory where the `assignment.json` file lives).

Expand Down
17 changes: 10 additions & 7 deletions internal/common/filespec.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,17 @@ func (this *FileSpec) copyPaths(baseDir string, destDir string, onlyContents boo
return fmt.Errorf("No targets found for the path '%s'.", this.Path)
}

if util.IsFile(destPath) && len(paths) > 1 {
return fmt.Errorf("Cannot copy multiple targets into the existing file '%s'.", destDir)
}
// Ensure destPath is a directory if there are multiple paths.
if len(paths) > 1 {
if util.IsFile(destPath) {
return fmt.Errorf("Cannot copy multiple targets into the existing file '%s'.", destDir)
}

if !util.PathExists(destPath) && len(paths) > 1 {
err := util.MkDir(destPath)
if err != nil {
return fmt.Errorf("Failed to make a directory for the Filespec at path '%s': '%v'.", destPath, err)
if !util.PathExists(destPath) {
err := util.MkDir(destPath)
if err != nil {
return fmt.Errorf("Failed to create a directory for the Filespec at path '%s': '%v'.", destPath, err)
}
}
}

Expand Down

0 comments on commit e0a2c0b

Please sign in to comment.