-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: Fix the failure to back up file names containing Spaces for sche… #8263
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,8 +83,8 @@ func (u *CronjobService) handleWebsite(cronjob model.Cronjob, startTime time.Tim | |
| record.Name = web.Alias | ||
| record.DetailName = web.Alias | ||
| record.DownloadAccountID, record.SourceAccountIDs = cronjob.DownloadAccountID, cronjob.SourceAccountIDs | ||
| backupDir := path.Join(global.Dir.TmpDir, fmt.Sprintf("website/%s", web.PrimaryDomain)) | ||
| record.FileName = fmt.Sprintf("website_%s_%s.tar.gz", web.PrimaryDomain, startTime.Format(constant.DateTimeSlimLayout)+common.RandStrAndNum(5)) | ||
| backupDir := path.Join(global.Dir.TmpDir, fmt.Sprintf("website/%s", web.Alias)) | ||
| 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 | ||
| } | ||
|
Member
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. The changes made seem to be focused on improving the naming consistency between
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.
Member
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. The code snippet you provided has two primary differences to consider:
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. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -768,7 +768,7 @@ func (f FileOp) TarGzFilesWithCompressPro(list []string, dst, secret string) err | |
|
|
||
| var filelist []string | ||
| for _, item := range list { | ||
| filelist = append(filelist, "-C "+path.Dir(item)+" "+path.Base(item)) | ||
| filelist = append(filelist, "-C '"+path.Dir(item)+"' '"+path.Base(item)+"' ") | ||
| } | ||
| commands := "" | ||
| if len(secret) != 0 { | ||
|
Member
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. 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 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:
This should resolve potential issues related to incorrect formatting due to leading/trailing spaces.
Member
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. There is an issue with the way paths containing spaces around directory names and filenames are processed. The To fix this, you should add quotes around each element of 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.
Member
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. The provided Go function
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:
This should make the function safer and more maintainable, especially when dealing with sensitive information like passwords. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1290,6 +1290,7 @@ const message = { | |
| settings: 'Setting', | ||
| cronjobs: 'Cronjob', | ||
| databases: 'Database', | ||
| waf: 'WAF', | ||
| licenses: 'License', | ||
| nodes: 'Node', | ||
| commands: 'Quick Commands', | ||
|
Member
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. No irregularities or optimizations are present in the provided code snippet. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,8 +43,8 @@ import { onMounted, ref } from 'vue'; | |
|
|
||
| defineOptions({ name: 'OpDialog' }); | ||
|
|
||
| const checkAll = ref(false); | ||
| const isIndeterminate = ref(true); | ||
| const checkAll = ref(); | ||
| const isIndeterminate = ref(false); | ||
| const checkedItems = ref([]); | ||
| const list = ref([]); | ||
|
|
||
|
|
@@ -58,7 +58,6 @@ const acceptParams = (props: DialogProps): void => { | |
| checkAll.value = false; | ||
| checkedItems.value = []; | ||
| list.value = props.list; | ||
| checkAll.value = true; | ||
| open.value = true; | ||
| }; | ||
|
|
||
|
Member
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. The modified code makes some changes to how
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. |
||
|
|
||
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.
There is one small adjustment to make:
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.