-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Makes sure JMX jar is installed and rolled back properly #600
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ import ( | |
|
||
// CopyFile copies the file from pathIn to pathOut. | ||
// If the file does not exist, it is created. If the file does exist, it is truncated before writing. | ||
func CopyFile(logger *zap.Logger, pathIn, pathOut string, overwrite bool) error { | ||
func CopyFile(logger *zap.Logger, pathIn, pathOut string, overwrite bool, useInFilePermBackup bool) error { | ||
pathInClean := filepath.Clean(pathIn) | ||
|
||
// Open the input file for reading. | ||
|
@@ -43,21 +43,41 @@ func CopyFile(logger *zap.Logger, pathIn, pathOut string, overwrite bool) error | |
|
||
pathOutClean := filepath.Clean(pathOut) | ||
fileMode := fs.FileMode(0600) | ||
|
||
flags := os.O_CREATE | os.O_WRONLY | ||
if overwrite { | ||
// If we are OK to overwrite, we will truncate the file on open | ||
flags |= os.O_TRUNC | ||
|
||
// Save old file's permissions and delete it first if it exists | ||
fileOutInfo, _ := os.Stat(pathOutClean) | ||
if fileOutInfo != nil { | ||
fileMode = fileOutInfo.Mode() | ||
// Try to save old file's permissions | ||
outFileInfo, _ := os.Stat(pathOutClean) | ||
if outFileInfo != nil { | ||
fileMode = outFileInfo.Mode() | ||
} else if useInFilePermBackup { | ||
// Use the new file's permissions as a backup and don't fail on error (best chance for rollback) | ||
inFileInfo, err := inFile.Stat() | ||
switch { | ||
case err != nil: | ||
logger.Error("failed to retrieve fileinfo for input file", zap.Error(err)) | ||
case inFileInfo != nil: | ||
fileMode = inFileInfo.Mode() | ||
} | ||
} | ||
|
||
// Remove old file to prevent issues with mac | ||
if err = os.Remove(pathOutClean); err != nil { | ||
logger.Debug("Failed to remove output file", zap.Error(err)) | ||
} | ||
_ = os.Remove(pathOutClean) | ||
} else { | ||
// This flag will make OpenFile error if the file already exists | ||
flags |= os.O_EXCL | ||
|
||
// Use the new file's permissions and fail if there's an issue (want to fail for backup) | ||
inFileInfo, err := inFile.Stat() | ||
if err != nil { | ||
return fmt.Errorf("failed to retrive fileinfo for input file: %w", err) | ||
} | ||
|
||
fileMode = inFileInfo.Mode() | ||
Comment on lines
+73
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we always want to use the input files's mode in this case, or only when the |
||
} | ||
|
||
// Open the output file, creating it if it does not exist and truncating it. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is right, but does it make sense to always prefer the destination file's permissions, even when
useInFilePermBackup
is true? The logic just feels off to me for some reason.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah...that's a good point. If the old file exists there's really no reason we won't get it's permissions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. it's all a little confusing for sure. ultimately we have 3 cases where we use this copy method.