Merge pull request #112803 from pohly/pod-io-rename

e2e storage: add Rename to PodIO
This commit is contained in:
Kubernetes Prow Robot 2022-09-30 06:28:29 -07:00 committed by GitHub
commit c5ab06f4c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -71,6 +71,9 @@ type DirIO interface {
Mkdir(path string) error
// RemoveAll removes the path and everything contained inside it. It's not an error if the path does not exist.
RemoveAll(path string) error
// Rename changes the name of a file or directory. The parent directory
// of newPath must exist.
Rename(oldPath, newPath string) error
}
type OSDirIO struct{}
@ -97,6 +100,10 @@ func (o OSDirIO) RemoveAll(path string) error {
return os.RemoveAll(path)
}
func (o OSDirIO) Rename(oldPath, newPath string) error {
return os.Rename(oldPath, newPath)
}
// Service is the CSI Mock service provider.
type Service interface {
csi.ControllerServer

View File

@ -70,6 +70,14 @@ func (p PodDirIO) CreateFile(path string, content io.Reader) error {
return nil
}
func (p PodDirIO) Rename(oldPath, newPath string) error {
_, stderr, err := p.execute([]string{"mv", oldPath, newPath}, nil)
if err != nil {
return fmt.Errorf("rename %q -> %q: stderr=%q, %v", oldPath, newPath, stderr, err)
}
return nil
}
func (p PodDirIO) RemoveAll(path string) error {
_, stderr, err := p.execute([]string{"rm", "-rf", path}, nil)
if err != nil {