Commit d223c4be authored by Michelle Au's avatar Michelle Au

Delete EmptyDir volume directly instead of renaming the directory.

The volume operation executor can handle duplicate requests on the same volume now.
parent d2d84da0
...@@ -329,11 +329,9 @@ func (ed *emptyDir) TearDownAt(dir string) error { ...@@ -329,11 +329,9 @@ func (ed *emptyDir) TearDownAt(dir string) error {
} }
func (ed *emptyDir) teardownDefault(dir string) error { func (ed *emptyDir) teardownDefault(dir string) error {
tmpDir, err := volume.RenameDirectory(dir, ed.volName+".deleting~") // Renaming the directory is not required anymore because the operation executor
if err != nil { // now handles duplicate operations on the same volume
return err err := os.RemoveAll(dir)
}
err = os.RemoveAll(tmpDir)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -17,14 +17,8 @@ limitations under the License. ...@@ -17,14 +17,8 @@ limitations under the License.
package volume package volume
import ( import (
"io"
"io/ioutil"
"os"
filepath "path/filepath"
"runtime"
"time" "time"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
...@@ -234,96 +228,3 @@ func IsDeletedVolumeInUse(err error) bool { ...@@ -234,96 +228,3 @@ func IsDeletedVolumeInUse(err error) bool {
func (err deletedVolumeInUseError) Error() string { func (err deletedVolumeInUseError) Error() string {
return string(err) return string(err)
} }
func RenameDirectory(oldPath, newName string) (string, error) {
newPath, err := ioutil.TempDir(filepath.Dir(oldPath), newName)
if err != nil {
return "", err
}
// os.Rename call fails on windows (https://github.com/golang/go/issues/14527)
// Replacing with copyFolder to the newPath and deleting the oldPath directory
if runtime.GOOS == "windows" {
err = copyFolder(oldPath, newPath)
if err != nil {
glog.Errorf("Error copying folder from: %s to: %s with error: %v", oldPath, newPath, err)
return "", err
}
os.RemoveAll(oldPath)
return newPath, nil
}
err = os.Rename(oldPath, newPath)
if err != nil {
return "", err
}
return newPath, nil
}
func copyFolder(source string, dest string) (err error) {
fi, err := os.Lstat(source)
if err != nil {
glog.Errorf("Error getting stats for %s. %v", source, err)
return err
}
err = os.MkdirAll(dest, fi.Mode())
if err != nil {
glog.Errorf("Unable to create %s directory %v", dest, err)
}
directory, _ := os.Open(source)
defer directory.Close()
objects, err := directory.Readdir(-1)
for _, obj := range objects {
if obj.Mode()&os.ModeSymlink != 0 {
continue
}
sourceFilePointer := source + "\\" + obj.Name()
destinationFilePointer := dest + "\\" + obj.Name()
if obj.IsDir() {
err = copyFolder(sourceFilePointer, destinationFilePointer)
if err != nil {
return err
}
} else {
err = copyFile(sourceFilePointer, destinationFilePointer)
if err != nil {
return err
}
}
}
return
}
func copyFile(source string, dest string) (err error) {
sourceFile, err := os.Open(source)
if err != nil {
return err
}
defer sourceFile.Close()
destFile, err := os.Create(dest)
if err != nil {
return err
}
defer destFile.Close()
_, err = io.Copy(destFile, sourceFile)
if err == nil {
sourceInfo, err := os.Stat(source)
if err != nil {
err = os.Chmod(dest, sourceInfo.Mode())
}
}
return
}
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