diff options
Diffstat (limited to 'weed/storage/disk_location.go')
| -rw-r--r-- | weed/storage/disk_location.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/weed/storage/disk_location.go b/weed/storage/disk_location.go index e92810022..ae2a36296 100644 --- a/weed/storage/disk_location.go +++ b/weed/storage/disk_location.go @@ -14,6 +14,7 @@ import ( "github.com/chrislusf/seaweedfs/weed/storage/needle" "github.com/chrislusf/seaweedfs/weed/storage/types" "github.com/chrislusf/seaweedfs/weed/util" + "github.com/google/uuid" ) type DiskLocation struct { @@ -33,6 +34,29 @@ type DiskLocation struct { isDiskSpaceLow bool } +func GenerateDirUUID(dir string) (dirUUIDString string, err error) { + glog.V(1).Infof("Getting UUID of volume directory:%s", dir) + dirUUIDString = "" + fileName := dir + "/volume.uuid" + if !util.FileExists(fileName) { + dirUUID, _ := uuid.NewRandom() + dirUUIDString = dirUUID.String() + writeErr := util.WriteFile(fileName, []byte(dirUUIDString), 0644) + if writeErr != nil { + glog.Warningf("failed to write UUID to %s : %v", fileName, writeErr) + return "", fmt.Errorf("failed to write UUID to %s : %v", fileName, writeErr) + } + } else { + uuidData, readErr := os.ReadFile(fileName) + if readErr != nil { + glog.Warningf("failed to read UUID from %s : %v", fileName, readErr) + return "", fmt.Errorf("failed to read UUID from %s : %v", fileName, readErr) + } + dirUUIDString = string(uuidData) + } + return dirUUIDString, nil +} + func NewDiskLocation(dir string, maxVolumeCount int, minFreeSpace util.MinFreeSpace, idxDir string, diskType types.DiskType) *DiskLocation { dir = util.ResolvePath(dir) if idxDir == "" { |
