This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
124 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"strconv" | ||
"strings" | ||
|
||
"os" | ||
|
||
"github.com/blablacar/dgr/dgr/common" | ||
"github.com/n0rad/go-erlog/data" | ||
"github.com/n0rad/go-erlog/errs" | ||
"github.com/n0rad/go-erlog/logs" | ||
) | ||
|
||
var pathCp = "/cp" | ||
|
||
func (aci *Aci) Cp(args []string) error { | ||
logs.WithF(aci.fields).Debug("Copy") | ||
if len(args) != 2 { | ||
return errs.With("cp requires 2 arguments") | ||
} | ||
if args[0][0] == '/' { | ||
args[0] = args[0][1:] | ||
} | ||
|
||
cpDir := aci.target + pathCp | ||
if err := os.MkdirAll(cpDir, 0755); err != nil { | ||
return errs.WithEF(err, data.WithField("dir", cpDir), "Failed to create directory") | ||
} | ||
defer func(dir string) { | ||
os.RemoveAll(dir) | ||
}(cpDir) | ||
|
||
stashes := strings.Count(args[0], "/") | ||
if err := tarExec( | ||
"xf", | ||
aci.target+pathImageAci, | ||
"--strip-components="+strconv.Itoa(stashes+1), | ||
"-C", | ||
cpDir, | ||
"rootfs/"+args[0], | ||
); err != nil { | ||
return errs.WithE(err, "Failed to extract files from aci") | ||
} | ||
|
||
giveBackUserRights(cpDir) | ||
|
||
files, err := ioutil.ReadDir(cpDir) | ||
if err != nil { | ||
return errs.WithEF(err, data.WithField("dir", cpDir), "Cannot read directory") | ||
} | ||
|
||
for _, f := range files { | ||
from := cpDir + "/" + f.Name() | ||
to := args[1] + "/" + f.Name() | ||
if err := common.ExecCmd("cp", "-R", "--preserve=all", from, to); err != nil { | ||
return errs.WithEF(err, data.WithField("from", from). | ||
WithField("to", to), | ||
"Failed to move file") | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "github.com/n0rad/go-erlog/errs" | ||
|
||
func (p *Pod) Cp(args []string) error { | ||
return errs.With("Pod cp is not implemented") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/blablacar/dgr/dgr/common" | ||
"github.com/n0rad/go-erlog/data" | ||
"github.com/n0rad/go-erlog/errs" | ||
"github.com/n0rad/go-erlog/logs" | ||
) | ||
|
||
func tarExec(args ...string) error { | ||
out, stderr, err := common.ExecCmdGetStdoutAndStderr("tar", args...) | ||
if err != nil { | ||
return errs.WithEF(err, data. | ||
WithField("stdout", out). | ||
WithField("stderr", stderr), "Tar update failed") | ||
} | ||
if logs.IsDebugEnabled() { | ||
println(out) | ||
} | ||
return nil | ||
} |