MCPcopy
hub / github.com/cubefs/cubefs / RemoveAll

Method RemoveAll

datanode/partition.go:829–858  ·  view source on GitHub ↗
(force bool)

Source from the content-addressed store, hash-verified

827}
828
829func (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.
861func (dp *DataPartition) PersistMetadata() (err error) {

Calls 9

PathMethod · 0.95
infoMethod · 0.95
LogInfofFunction · 0.92
LockMethod · 0.80
DirMethod · 0.80
AddBackupPartitionDirMethod · 0.80
JoinMethod · 0.65
RenameMethod · 0.65
UnlockMethod · 0.45