Skip to content

incus/file: Move from path to filepath #1647

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

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions cmd/incus/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"os"
"os/exec"
"os/signal"
"path"
"path/filepath"
"slices"
"strconv"
Expand Down Expand Up @@ -166,7 +165,7 @@ func (c *cmdFileCreate) Run(cmd *cobra.Command, args []string) error {
resource := resources[0]

// re-add leading / that got stripped by the SplitN
targetPath := path.Clean("/" + pathSpec[1])
targetPath := filepath.Clean("/" + pathSpec[1])

// normalization may reveal that path is still a dir, e.g. /.
if strings.HasSuffix(targetPath, "/") {
Expand Down Expand Up @@ -216,7 +215,7 @@ func (c *cmdFileCreate) Run(cmd *cobra.Command, args []string) error {

// Create needed paths if requested
if c.file.flagMkdir {
err = c.file.recursiveMkdir(resource.server, resource.name, path.Dir(targetPath), nil, int64(uid), int64(gid))
err = c.file.recursiveMkdir(resource.server, resource.name, filepath.Dir(targetPath), nil, int64(uid), int64(gid))
if err != nil {
return err
}
Expand Down Expand Up @@ -600,7 +599,7 @@ func (c *cmdFilePull) Run(cmd *cobra.Command, args []string) error {

var targetPath string
if targetIsDir {
targetPath = path.Join(target, path.Base(pathSpec[1]))
targetPath = filepath.Join(target, filepath.Base(pathSpec[1]))
} else {
targetPath = target
}
Expand Down Expand Up @@ -734,7 +733,7 @@ func (c *cmdFilePush) Run(cmd *cobra.Command, args []string) error {
// re-add leading / that got stripped by the SplitN
targetPath := "/" + pathSpec[1]
// clean various /./, /../, /////, etc. that users add (#2557)
targetPath = path.Clean(targetPath)
targetPath = filepath.Clean(targetPath)

// normalization may reveal that path is still a dir, e.g. /.
if strings.HasSuffix(targetPath, "/") {
Expand Down Expand Up @@ -846,7 +845,7 @@ func (c *cmdFilePush) Run(cmd *cobra.Command, args []string) error {
for _, f := range files {
fpath := targetPath
if targetIsDir {
fpath = path.Join(fpath, path.Base(f.Name()))
fpath = filepath.Join(fpath, filepath.Base(f.Name()))
}

// Create needed paths if requested
Expand All @@ -868,7 +867,7 @@ func (c *cmdFilePush) Run(cmd *cobra.Command, args []string) error {
}
}

err = c.file.recursiveMkdir(resource.server, resource.name, path.Dir(fpath), nil, int64(uid), int64(gid))
err = c.file.recursiveMkdir(resource.server, resource.name, filepath.Dir(fpath), nil, int64(uid), int64(gid))
if err != nil {
return err
}
Expand Down Expand Up @@ -1053,7 +1052,7 @@ func (c *cmdFile) recursivePullFile(d incus.InstanceServer, inst string, p strin
}

for _, ent := range resp.Entries {
nextP := path.Join(p, ent)
nextP := filepath.Join(p, ent)

err := c.recursivePullFile(d, inst, nextP, target)
if err != nil {
Expand Down Expand Up @@ -1136,7 +1135,7 @@ func (c *cmdFile) recursivePushFile(d incus.InstanceServer, inst string, source
}

// Prepare for file transfer
targetPath := path.Join(target, filepath.ToSlash(p[sourceLen:]))
targetPath := filepath.Join(target, filepath.ToSlash(p[sourceLen:]))
mode, uid, gid := internalIO.GetOwnerMode(fInfo)
args := incus.InstanceFileArgs{
UID: int64(uid),
Expand Down