Skip to content

Commit

Permalink
Merge pull request #7 from RobiNino/symlinks_branch
Browse files Browse the repository at this point in the history
Upload broken symlinks
  • Loading branch information
eyalbe4 authored Nov 5, 2018
2 parents ec51d3f + c5721e4 commit 1e5dda4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
3 changes: 1 addition & 2 deletions artifactory/services/fspatterns/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 8 additions & 7 deletions artifactory/services/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions utils/io/fileutils/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ 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)
}

// Check if path points at a file.
// 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
Expand All @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 1e5dda4

Please sign in to comment.