Skip to content

Commit f620e20

Browse files
committed
chore(volumes): merge dest dir
1 parent 7667857 commit f620e20

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

cmd/volumes.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ func (d *DryccCmd) volumesClientLs(appID, vol string) error {
284284
}
285285

286286
func (d *DryccCmd) volumesClientGetAll(client *drycc.Client, appID, volumeID, volumePath, localPath string) error {
287+
if _, err := os.Stat(localPath); err != nil && os.IsNotExist(err) {
288+
os.MkdirAll(localPath, os.ModePerm)
289+
}
287290
dirs, _, err := volumes.ListDir(client, appID, volumeID, volumePath, 3000)
288291
if err != nil {
289292
return err
@@ -371,7 +374,7 @@ func (d *DryccCmd) volumesClientCp(appID, src, dst string) error {
371374
if err != nil {
372375
return err
373376
}
374-
return d.volumesClientGetAll(s.Client, appID, volumeID, volumePath, dst)
377+
return d.volumesClientGetAll(s.Client, appID, volumeID, volumePath, mergeDestDir(dst, src))
375378
} else if strings.HasPrefix(dst, "vol://") {
376379
volumeID, volumePath, err := parseVol(dst)
377380
if err != nil {
@@ -384,7 +387,7 @@ func (d *DryccCmd) volumesClientCp(appID, src, dst string) error {
384387
} else if strings.Contains(fmt.Sprint(err), "no such file or directory") {
385388
return err
386389
}
387-
return d.volumesClientPostAll(s.Client, appID, volumeID, volumePath, src)
390+
return d.volumesClientPostAll(s.Client, appID, volumeID, mergeDestDir(volumePath, src), src)
388391
}
389392
return nil
390393
}
@@ -437,6 +440,15 @@ func parseVol(vol string) (string, string, error) {
437440
return u.Host, strings.TrimPrefix(u.Path, "/"), nil
438441
}
439442

443+
// mergeDestDir merge dest dir
444+
func mergeDestDir(prefix, dir string) string {
445+
if !strings.HasSuffix(dir, "/") {
446+
names := strings.Split(dir, "/")
447+
return strings.Join([]string{prefix, names[len(names)-1]}, "/")
448+
}
449+
return prefix
450+
}
451+
440452
// printVolumes format volume data
441453
func printVolumes(d *DryccCmd, volumes api.Volumes) {
442454
table := d.getDefaultFormatTable([]string{"NAME", "OWNER", "TYPE", "PTYPE", "PATH", "SIZE"})

0 commit comments

Comments
 (0)