Commit 65b48aae authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #48672 from dixudx/resolve_hard_coded_path_sep_atomic

Automatic merge from submit-queue (batch tested with PRs 48672, 47140, 48709, 48786, 48757) use built-in path separator instead of hard coded **What this PR does / why we need it**: We should use built-in path separator to avoid hard coded strings. **Which issue this PR fixes** : **Special notes for your reviewer**: **Release note**: ```release-note None ```
parents 8e5584fe a76ccf5a
...@@ -311,11 +311,7 @@ func (w *AtomicWriter) pathsToRemove(payload map[string]FileProjection) (sets.St ...@@ -311,11 +311,7 @@ func (w *AtomicWriter) pathsToRemove(payload map[string]FileProjection) (sets.St
} }
relativePath := strings.TrimPrefix(path, w.targetDir) relativePath := strings.TrimPrefix(path, w.targetDir)
if runtime.GOOS == "windows" { relativePath = strings.TrimPrefix(relativePath, string(os.PathSeparator))
relativePath = strings.TrimPrefix(relativePath, "\\")
} else {
relativePath = strings.TrimPrefix(relativePath, "/")
}
if strings.HasPrefix(relativePath, "..") { if strings.HasPrefix(relativePath, "..") {
return nil return nil
} }
...@@ -339,7 +335,7 @@ func (w *AtomicWriter) pathsToRemove(payload map[string]FileProjection) (sets.St ...@@ -339,7 +335,7 @@ func (w *AtomicWriter) pathsToRemove(payload map[string]FileProjection) (sets.St
for subPath := file; subPath != ""; { for subPath := file; subPath != ""; {
newPaths.Insert(subPath) newPaths.Insert(subPath)
subPath, _ = filepath.Split(subPath) subPath, _ = filepath.Split(subPath)
subPath = strings.TrimSuffix(subPath, "/") subPath = strings.TrimSuffix(subPath, string(os.PathSeparator))
} }
} }
glog.V(5).Infof("%s: new paths: %+v", w.targetDir, newPaths.List()) glog.V(5).Infof("%s: new paths: %+v", w.targetDir, newPaths.List())
...@@ -424,7 +420,7 @@ func (w *AtomicWriter) createUserVisibleFiles(payload map[string]FileProjection) ...@@ -424,7 +420,7 @@ func (w *AtomicWriter) createUserVisibleFiles(payload map[string]FileProjection)
// Since filepath.Split leaves a trailing path separator, in this // Since filepath.Split leaves a trailing path separator, in this
// example, dir = "foo/". In order to calculate the number of // example, dir = "foo/". In order to calculate the number of
// subdirectories, we must subtract 1 from the number returned by split. // subdirectories, we must subtract 1 from the number returned by split.
subDirs = len(strings.Split(dir, "/")) - 1 subDirs = len(strings.Split(dir, string(os.PathSeparator))) - 1
err := os.MkdirAll(path.Join(w.targetDir, dir), os.ModePerm) err := os.MkdirAll(path.Join(w.targetDir, dir), os.ModePerm)
if err != nil { if err != nil {
return err return err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment