| 827 | } |
| 828 | |
| 829 | func (dp *DataPartition) RemoveAll(force bool) (err error) { |
| 830 | dp.persistMetaMutex.Lock() |
| 831 | defer dp.persistMetaMutex.Unlock() |
| 832 | if force { |
| 833 | originalPath := dp.Path() |
| 834 | parent := path.Dir(originalPath) |
| 835 | fileName := path.Base(originalPath) |
| 836 | newFilename := BackupPartitionPrefix + fileName |
| 837 | newPath := fmt.Sprintf("%v-%v", path.Join(parent, newFilename), time.Now().Format("20060102150405")) |
| 838 | //_, err = os.Stat(newPath) |
| 839 | //if err == nil { |
| 840 | // newPathWithTimestamp := fmt.Sprintf("%v-%v", newPath, time.Now().Format("20060102150405")) |
| 841 | // err = os.Rename(newPath, newPathWithTimestamp) |
| 842 | // if err != nil { |
| 843 | // log.LogWarnf("action[Stop]:dp(%v) rename dir from %v to %v,err %v", dp.info(), newPath, newPathWithTimestamp, err) |
| 844 | // return err |
| 845 | // } |
| 846 | //} |
| 847 | err = os.Rename(originalPath, newPath) |
| 848 | if err == nil { |
| 849 | dp.path = newPath |
| 850 | dp.disk.AddBackupPartitionDir(dp.partitionID) |
| 851 | } |
| 852 | log.LogInfof("action[Stop]:dp(%v) rename dir from %v to %v,err %v", dp.info(), originalPath, newPath, err) |
| 853 | } else { |
| 854 | err = os.RemoveAll(dp.Path()) |
| 855 | log.LogInfof("action[Stop]:dp(%v) remove %v,err %v", dp.info(), dp.Path(), err) |
| 856 | } |
| 857 | return err |
| 858 | } |
| 859 | |
| 860 | // PersistMetadata persists the file metadata on the disk. |
| 861 | func (dp *DataPartition) PersistMetadata() (err error) { |