From c5721e45b61943008622a7a549ea242f427f1e46 Mon Sep 17 00:00:00 2001 From: robin Date: Mon, 5 Nov 2018 18:59:20 +0200 Subject: [PATCH] Upload broken symlinks - after eyals comments --- artifactory/services/fspatterns/utils.go | 3 +-- artifactory/services/upload.go | 15 ++++++++------- utils/io/fileutils/files.go | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/artifactory/services/fspatterns/utils.go b/artifactory/services/fspatterns/utils.go index b7d473258..3bf8acf00 100644 --- a/artifactory/services/fspatterns/utils.go +++ b/artifactory/services/fspatterns/utils.go @@ -85,9 +85,8 @@ func GetSingleFileToUpload(rootPath, targetPath string, flat, preserveSymLink bo if !strings.HasSuffix(targetPath, "/") { uploadPath = targetPath } else { - // If not preserving symlinks and symlink target is valid, use symlink target for upload - if !preserveSymLink && (symlinkPath != "") { + if !preserveSymLink && symlinkPath != "" { rootPath = symlinkPath } if flat { diff --git a/artifactory/services/upload.go b/artifactory/services/upload.go index 50064583b..785c53d4d 100644 --- a/artifactory/services/upload.go +++ b/artifactory/services/upload.go @@ -112,14 +112,15 @@ func addSymlinkProps(artifact clientutils.Artifact, uploadParams UploadParams) ( sha1Property := "" fileInfo, err := os.Stat(artifact.LocalPath) if err != nil { - if !os.IsNotExist(err) { // If error occurred, but not due to nonexistence of Symlink target -> return empty + // If error occurred, but not due to nonexistence of Symlink target -> return empty + if !os.IsNotExist(err) { return "", err } - } else if !fileInfo.IsDir() { // If Symlink target exists -> get SHA1 if isn't a directory + // If Symlink target exists -> get SHA1 if isn't a directory + } else if !fileInfo.IsDir() { file, err := os.Open(artifact.LocalPath) - errorutils.CheckError(err) if err != nil { - return "", err + return "", errorutils.CheckError(err) } defer file.Close() checksumInfo, err := checksum.Calc(file, checksum.SHA1) @@ -297,8 +298,8 @@ func addPropsToTargetPath(targetPath, props, debConfig string) (string, error) { return strings.Join([]string{targetPath, properties.ToEncodedString()}, ";"), nil } -func prepareUploadData(baseTargetPath, localPath, props string, uploadParams UploadParams, logMsgPrefix string) (fileInfo os.FileInfo, targetPath string, fileName string, err error) { - fileName, _ = fileutils.GetFileAndDirFromPath(localPath) +func prepareUploadData(localPath, baseTargetPath, props string, uploadParams UploadParams, logMsgPrefix string) (fileInfo os.FileInfo, targetPath string, fileName string, err error) { + fileName, _ = fileutils.GetFileAndDirFromPath(baseTargetPath) targetPath, err = addPropsToTargetPath(baseTargetPath, props, uploadParams.GetDebian()) if errorutils.CheckError(err) != nil { return @@ -313,7 +314,7 @@ func prepareUploadData(baseTargetPath, localPath, props string, uploadParams Upl // Uploads the file in the specified local path to the specified target path. // Returns true if the file was successfully uploaded. func (us *UploadService) uploadFile(localPath, targetPath, props string, uploadParams UploadParams, logMsgPrefix string) (utils.FileInfo, bool, error) { - fileInfo, targetPath, fileName, err := prepareUploadData(targetPath, localPath, props, uploadParams, logMsgPrefix) + fileInfo, targetPath, fileName, err := prepareUploadData(localPath, targetPath, props, uploadParams, logMsgPrefix) if err != nil { return utils.FileInfo{}, false, err } diff --git a/utils/io/fileutils/files.go b/utils/io/fileutils/files.go index 6a9e3b985..8feb1bb6d 100644 --- a/utils/io/fileutils/files.go +++ b/utils/io/fileutils/files.go @@ -31,7 +31,7 @@ func GetFileSeparator() string { // If path points at a symlink and `preserveSymLink == true`, // function will return `true` regardless of the symlink target func IsPathExists(path string, preserveSymLink bool) bool { - _, err := GetFileInfoByPreserveSymLink(path, preserveSymLink) + _, err := GetFileInfo(path, preserveSymLink) return !os.IsNotExist(err) } @@ -39,7 +39,7 @@ func IsPathExists(path string, preserveSymLink bool) bool { // If path points at a symlink and `preserveSymLink == true`, // function will return `true` regardless of the symlink target func IsFileExists(path string, preserveSymLink bool) (bool, error) { - fileInfo, err := GetFileInfoByPreserveSymLink(path, preserveSymLink) + fileInfo, err := GetFileInfo(path, preserveSymLink) if err != nil { if os.IsNotExist(err) { // If doesn't exist, don't omit an error return false, nil @@ -53,7 +53,7 @@ func IsFileExists(path string, preserveSymLink bool) (bool, error) { // If path points at a symlink and `preserveSymLink == true`, // function will return `false` regardless of the symlink target func IsDirExists(path string, preserveSymLink bool) (bool, error) { - fileInfo, err := GetFileInfoByPreserveSymLink(path, preserveSymLink) + fileInfo, err := GetFileInfo(path, preserveSymLink) if err != nil { if os.IsNotExist(err) { // If doesn't exist, don't omit an error return false, nil @@ -65,7 +65,7 @@ func IsDirExists(path string, preserveSymLink bool) (bool, error) { // Get the file info of the file in path. // If path points at a symlink and `preserveSymLink == true`, return the file info of the symlink instead -func GetFileInfoByPreserveSymLink(path string, preserveSymLink bool) (fileInfo os.FileInfo, err error) { +func GetFileInfo(path string, preserveSymLink bool) (fileInfo os.FileInfo, err error) { if preserveSymLink { fileInfo, err = os.Lstat(path) } else {