feat(remote download): sanitize file names with special characters (#2648)
This commit is contained in:
2
assets
2
assets
Submodule assets updated: aa80ca5bb2...3a6a22bb45
@@ -8,6 +8,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@@ -318,7 +319,7 @@ func (m *RemoteDownloadTask) slaveTransfer(ctx context.Context, dep dependency.D
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
dst := dstUri.JoinRaw(f.Name)
|
dst := dstUri.JoinRaw(sanitizeFileName(f.Name))
|
||||||
src := path.Join(m.state.Status.SavePath, f.Name)
|
src := path.Join(m.state.Status.SavePath, f.Name)
|
||||||
payload.Files = append(payload.Files, SlaveUploadEntity{
|
payload.Files = append(payload.Files, SlaveUploadEntity{
|
||||||
Src: src,
|
Src: src,
|
||||||
@@ -437,9 +438,10 @@ func (m *RemoteDownloadTask) masterTransfer(ctx context.Context, dep dependency.
|
|||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
dst := dstUri.JoinRaw(file.Name)
|
sanitizedName := sanitizeFileName(file.Name)
|
||||||
|
dst := dstUri.JoinRaw(sanitizedName)
|
||||||
src := filepath.FromSlash(path.Join(m.state.Status.SavePath, file.Name))
|
src := filepath.FromSlash(path.Join(m.state.Status.SavePath, file.Name))
|
||||||
m.l.Info("Uploading file %s to %s...", src, file.Name, dst)
|
m.l.Info("Uploading file %s to %s...", src, sanitizedName, dst)
|
||||||
|
|
||||||
progressKey := fmt.Sprintf("%s%d", ProgressTypeUploadSinglePrefix, workerId)
|
progressKey := fmt.Sprintf("%s%d", ProgressTypeUploadSinglePrefix, workerId)
|
||||||
m.Lock()
|
m.Lock()
|
||||||
@@ -538,7 +540,7 @@ func (m *RemoteDownloadTask) validateFiles(ctx context.Context, dep dependency.D
|
|||||||
|
|
||||||
validateArgs := lo.Map(selectedFiles, func(f downloader.TaskFile, _ int) fs.PreValidateFile {
|
validateArgs := lo.Map(selectedFiles, func(f downloader.TaskFile, _ int) fs.PreValidateFile {
|
||||||
return fs.PreValidateFile{
|
return fs.PreValidateFile{
|
||||||
Name: f.Name,
|
Name: sanitizeFileName(f.Name),
|
||||||
Size: f.Size,
|
Size: f.Size,
|
||||||
OmitName: f.Name == "",
|
OmitName: f.Name == "",
|
||||||
}
|
}
|
||||||
@@ -637,3 +639,8 @@ func (m *RemoteDownloadTask) Progress(ctx context.Context) queue.Progresses {
|
|||||||
}
|
}
|
||||||
return m.progress
|
return m.progress
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sanitizeFileName(name string) string {
|
||||||
|
r := strings.NewReplacer("\\", "_", ":", "_", "*", "_", "?", "_", "\"", "_", "<", "_", ">", "_", "|", "_")
|
||||||
|
return r.Replace(name)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user