When id is empty for overlay2/overlay, do not remove the directories.
Signed-off-by: fanjiyun <fan.jiyun@zte.com.cn> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
d47c45175b
commit
0e8f96e317
2 changed files with 9 additions and 1 deletions
|
@ -366,6 +366,9 @@ func (d *Driver) dir(id string) string {
|
|||
|
||||
// Remove cleans the directories that are created for this id.
|
||||
func (d *Driver) Remove(id string) error {
|
||||
if id == "" {
|
||||
return fmt.Errorf("refusing to remove the directories: id is empty")
|
||||
}
|
||||
d.locker.Lock(id)
|
||||
defer d.locker.Unlock(id)
|
||||
return system.EnsureRemoveAll(d.dir(id))
|
||||
|
|
|
@ -513,12 +513,17 @@ func (d *Driver) getLowerDirs(id string) ([]string, error) {
|
|||
|
||||
// Remove cleans the directories that are created for this id.
|
||||
func (d *Driver) Remove(id string) error {
|
||||
if id == "" {
|
||||
return fmt.Errorf("refusing to remove the directories: id is empty")
|
||||
}
|
||||
d.locker.Lock(id)
|
||||
defer d.locker.Unlock(id)
|
||||
dir := d.dir(id)
|
||||
lid, err := ioutil.ReadFile(path.Join(dir, "link"))
|
||||
if err == nil {
|
||||
if err := os.RemoveAll(path.Join(d.home, linkDir, string(lid))); err != nil {
|
||||
if len(lid) == 0 {
|
||||
logrus.WithField("storage-driver", "overlay2").Errorf("refusing to remove empty link for layer %v", id)
|
||||
} else if err := os.RemoveAll(path.Join(d.home, linkDir, string(lid))); err != nil {
|
||||
logrus.WithField("storage-driver", "overlay2").Debugf("Failed to remove link: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue