fix: Fix the failure to back up file names containing Spaces for sche…#8263
fix: Fix the failure to back up file names containing Spaces for sche…#8263wanghe-fit2cloud merged 1 commit intodev-v2from
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| record.FileName = fmt.Sprintf("website_%s_%s.tar.gz", web.Alias, startTime.Format(constant.DateTimeSlimLayout)+common.RandStrAndNum(5)) | ||
| if err := handleWebsiteBackup(&web, backupDir, record.FileName, cronjob.ExclusionRules, cronjob.Secret, taskID); err != nil { | ||
| return err | ||
| } |
There was a problem hiding this comment.
There is one small adjustment to make:
-record.FileName = fmt.Sprintf("website_%s_%s.tar.gz", web.PrimaryDomain, startTime.Format(constant.DateTimeSlimLayout)+common.RandStrAndNum(5))
+record.FileName = fmt.Sprintf("website_%s_%s.tar.gz", web.Alias, startTime.Format(constant.DateTimeSlimLayout))The original version includes common.RandStrAndNum(5) in the filename if there are exclusion rules (cronjob.ExclusionRules). If these exclusion rules are not present, this might cause errors since it adds unnecessary randomness. By removing it when there are no exclusion rules, you avoid potential issues.
Overall, the code looks mostly clean, but incorporating this minor modification ensures that filenames remain consistent regardless of whether exclusion rules apply.
| filelist = append(filelist, "-C '"+path.Dir(item)+"' '"+path.Base(item)+"' ") | ||
| } | ||
| commands := "" | ||
| if len(secret) != 0 { |
There was a problem hiding this comment.
There are no direct syntax errors in this code snippet. However, there is a minor issue with how path Base and Dir are being appended to the filelist. The path.Base should be enclosed in quotes if it contains special characters. Additionally, there might be unintended trailing spaces in some cases if path.Base doesn't contain separators.
Here's an optimized version:
func (f FileOp) TarGzFilesWithCompressPro(list []string, dst, secret string) error {
var filelist []string
for _, item := range list {
dir := path.Dir(item)
base := fmt.Sprintf("'%s'", filepath.Base(item)) // Use of ' ensures safe formatting
filelist = append(filelist, "-C", dir, base)
}
commands := ""
if len(secret) != 0 {
// rest of the function remains unchangedKey changes:
- Directly construct the final strings using
%qinstead of string concatenation to ensure proper quoting. - Remove any unnecessary spaces from the final command arguments.
This should resolve potential issues related to incorrect formatting due to leading/trailing spaces.
636b72a to
16fdbdf
Compare
| record.FileName = fmt.Sprintf("website_%s_%s.tar.gz", web.Alias, startTime.Format(constant.DateTimeSlimLayout)+common.RandStrAndNum(5)) | ||
| if err := handleWebsiteBackup(&web, backupDir, record.FileName, cronjob.ExclusionRules, cronjob.Secret, taskID); err != nil { | ||
| return err | ||
| } |
There was a problem hiding this comment.
The changes made seem to be focused on improving the naming consistency between web.Alias and other variables used throughout the function. Here’s a concise summary of the modifications:
-
Update Backup Directory Names:
- Changed
"website/%s"to"website/%s", keeping both paths consistent.
- Changed
-
Update Record Field Names:
- Changed two occurrences where
record.Nameandrecord.DetailNamewere being set to useweb.Alias.
- Changed two occurrences where
No other issues or optimizations have been identified based on this small change. The rest of the code seems logically sound for handling website backups with specified details and exclusions.
| filelist = append(filelist, "-C '"+path.Dir(item)+"' '"+path.Base(item)+"' ") | ||
| } | ||
| commands := "" | ||
| if len(secret) != 0 { |
There was a problem hiding this comment.
There is an issue with the way paths containing spaces around directory names and filenames are processed. The append function appends strings directly without ensuring that they have quotes when needed, which could cause problems if some items contain special characters or spaces.
To fix this, you should add quotes around each element of filelist. Here's a suggested modification:
for _, item := range list {
filelist = append(filelist, "-C \""+path.Dir(item)+"\" \""+path.Base(item)+"\"")
}This ensures that both directories and files with spaces are handled correctly. Additionally, it prevents issues due to incorrect interpretation of shell commands.
| waf: 'WAF', | ||
| licenses: 'License', | ||
| nodes: 'Node', | ||
| commands: 'Quick Commands', |
There was a problem hiding this comment.
No irregularities or optimizations are present in the provided code snippet.
16fdbdf to
fe24fd1
Compare
| checkAll.value = true; | ||
| open.value = true; | ||
| }; | ||
|
|
There was a problem hiding this comment.
The modified code makes some changes to how checkAll and isIndeterminate are initialized. Here's a detailed analysis:
-
Initialization of
checkAll:- Before modification:
const checkAll = ref(false);
- After modification:
const checkAll = ref();
- Change:
Initial value changed fromfalsetoundefined. This might not be the best default choice since it can lead to undefined behavior when you use functions that rely on truthy/falsy values.
- Before modification:
-
Value Update Logic:
- Before modification:
if (list.length > 0) { checkAll.value = true; }
- After modification:
The conditionif (list.length > 0)is missing, which meanscheckAllwill always remain false unless explicitly set to true later.
- Before modification:
-
Optimization Suggestion:
Consider adding an early return statement after settingcheckedItems, especially ifacceptParamsis called often with empty lists:const acceptParams = (props: DialogProps): void => { list.value = props.list; checkedItems.value = props.checkedItems || []; if (!list.value.some(item => item.selected)) { // If no items are selected, ensure all are unchecked clearCheckedState(); } else if (allSelected()) { markAsFullyChecked(); } else { markAsInDeterminate(); } open.value = true; };
-
Further Improvements:
- Implement helper methods like
clearCheckedState(),markedAsFullyChecked(), andmarkAsInDeterminate()for better readability and maintainability.
- Implement helper methods like
These considerations help ensure robust functionality and clean code practices, although based solely on the provided modifications, they don't necessarily fix every issue identified without understanding deeper context.
| record.FileName = fmt.Sprintf("website_%s_%s.tar.gz", web.Alias, startTime.Format(constant.DateTimeSlimLayout)+common.RandStrAndNum(5)) | ||
| if err := handleWebsiteBackup(&web, backupDir, record.FileName, cronjob.ExclusionRules, cronjob.Secret, taskID); err != nil { | ||
| return err | ||
| } |
There was a problem hiding this comment.
The code snippet you provided has two primary differences to consider:
-
Temporary Directory Path: In the original code,
path.Join(global.Dir.TmpDir, fmt.Sprintf("website/%s", web.PrimaryDomain))is used. The updated version usesfmt.Sprintf("website/%s", web.Alias)instead. This change affects how websites are identified within temporary directories. -
File Name Format: Both versions use similar formatting but with different variable names (
web.Alias) for the file name. This ensures that backups will be named uniquely based on website aliases rather than their primary domains.
No significant potential issues were identified in this update. Optimization suggestions would include ensuring that these changes are thoroughly tested across various scenarios, especially handling edge cases where multiple domains might share the same alias. Additionally, maintaining consistency between primary domain usage throughout the application could benefit overall performance and data integrity.
| filelist = append(filelist, "-C '"+path.Dir(item)+"' '"+path.Base(item)+"' ") | ||
| } | ||
| commands := "" | ||
| if len(secret) != 0 { |
There was a problem hiding this comment.
The provided Go function TarGzFilesWithCompressPro has several issues that need to be addressed:
-
String Concatenation: The line
commands += "tar --gzip " + strings.Join(filelist, "")
concatenates a string with multiple file paths and other parts, but it does not add spaces between them efficiently.
-
Variable Formatting: When appending elements to the
filelist, there are extra spaces after each path component.filelist = append(filelist, "-C '+path.Dir(item)+'' '"+path.Base(item)+"'")
-
Path Handling: Ensure that the directory separation characters (
/vs\) match the operating system you are targeting, as this could lead to errors on different platforms. -
Error Handling: The error handling at the end is incomplete. You should return an appropriate error type from each method if something goes wrong during processing.
-
General Code Improvements:
- Consider using slices for more flexible operations rather than converting to strings and joining them again.
- Avoid unnecessary intermediate variables unless absolutely necessary.
Here's an improved version of the function address some of these issues:
func (f FileOp) TarGzFilesWithCompressPro(list []string, dst string, secret string) error {
var (
tarArgs []string
filePaths []string
)
for _, item := range list {
dir := filepath.Dir(item)
baseName := filepath.Base(item)
// Append both the directory and base name in quoted form
tarArgs = append(tarArgs, fmt.Sprintf("%q/%q", dir, baseName))
}
if len(secret) != 0 {
tarArgs = append(tarArgs, "--password="+secret)
}
// Use os/exec directly while specifying full arguments
cmd := exec.Command("tar",append([]string{"--gzip"}, tarArgs...)...)
err := cmd.Run()
return err
}Key Changes Made:
- Simplified Directory Path Construction: Used
filepath.Dirandfilepath.Basewhich handle OS-specific path separators correctly. - Efficient String Concatenation with Slices: Directly construct command args instead of building large concatenated strings.
- Added Secret Argument: Passed the secret argument to
tar. - Command Execution with
os/exec: Provided a clean and efficient way to execute the command without manually constructing a string.
This should make the function safer and more maintainable, especially when dealing with sensitive information like passwords.
|



No description provided.