Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions artifactory/services/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ func (ds *DownloadService) produceTasks(reader *content.ContentReader, downloadP
if err != nil {
return "", err
}
localPath, localFileName := fileutils.GetLocalPathAndFile(resultItem.Name, resultItem.Path, target, flat, placeholdersUsed)
localPath, localFileName, err := fileutils.GetLocalPathAndFile(resultItem.Name, resultItem.Path, target, flat, placeholdersUsed)
if err != nil {
return "", err
}
return filepath.Join(localPath, localFileName), nil
}
// The sort process omits results with local path that is identical to previous results.
Expand Down Expand Up @@ -563,7 +566,10 @@ func (ds *DownloadService) createFileHandlerFunc(downloadParams DownloadParams,
if err != nil {
return err
}
localPath, localFileName := fileutils.GetLocalPathAndFile(downloadData.Dependency.Name, downloadData.Dependency.Path, target, downloadData.Flat, placeholdersUsed)
localPath, localFileName, err := fileutils.GetLocalPathAndFile(downloadData.Dependency.Name, downloadData.Dependency.Path, target, downloadData.Flat, placeholdersUsed)
if err != nil {
return err
}
localFullPath := filepath.Join(localPath, localFileName)
if downloadData.Dependency.Type == string(utils.Folder) {
return createDir(localFullPath, logMsgPrefix)
Expand Down
28 changes: 26 additions & 2 deletions utils/io/fileutils/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,33 @@ func GetFileAndDirFromPath(path string) (fileName, dir string) {
return
}

func isDir(path string) (bool, error) {
info, err := os.Stat(path)
if os.IsNotExist(err) {
return false, nil // does not exist
}
if err != nil {
return false, err // some other error
}
return info.IsDir(), nil // check if it's a directory
}

// Get the local path and filename from original file name and path according to targetPath
func GetLocalPathAndFile(originalFileName, relativePath, targetPath string, flat bool, placeholdersUsed bool) (localTargetPath, fileName string) {
targetFileName, targetDirPath := GetFileAndDirFromPath(targetPath)
func GetLocalPathAndFile(originalFileName, relativePath, targetPath string, flat bool, placeholdersUsed bool) (localTargetPath, fileName string, err error) {
dir, err := isDir(targetPath)
if err != nil {
return
}

var targetFileName string
var targetDirPath string
if dir {
targetFileName = ""
targetDirPath = targetPath
} else {
targetFileName, targetDirPath = GetFileAndDirFromPath(targetPath)
}

// Remove double slashes and double backslashes that may appear in the path
localTargetPath = filepath.Clean(targetDirPath)
// When placeholders are used, the file path shouldn't be taken into account (or in other words, flat = true).
Expand Down
Loading