diff options
| author | Aleksey Kosov <rusyak777@list.ru> | 2025-02-24 18:58:43 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-24 07:58:43 -0800 |
| commit | ef4eda0761867d04c0908c43f51b2ef74f636a2a (patch) | |
| tree | bcdf60deb0ad37504a95ef045a70a38b57b1b41c /weed/storage/disk_location.go | |
| parent | be74548cb51f757a026be5909d35b819c62eecd1 (diff) | |
| download | seaweedfs-ef4eda0761867d04c0908c43f51b2ef74f636a2a.tar.xz seaweedfs-ef4eda0761867d04c0908c43f51b2ef74f636a2a.zip | |
added re-generating and writing the Volume UUID if it is empty (#6568)
Diffstat (limited to 'weed/storage/disk_location.go')
| -rw-r--r-- | weed/storage/disk_location.go | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/weed/storage/disk_location.go b/weed/storage/disk_location.go index dd78735d2..47f1b3d6f 100644 --- a/weed/storage/disk_location.go +++ b/weed/storage/disk_location.go @@ -40,21 +40,28 @@ type DiskLocation struct { func GenerateDirUuid(dir string) (dirUuidString string, err error) { glog.V(1).Infof("Getting uuid of volume directory:%s", dir) - dirUuidString = "" fileName := dir + "/vol_dir.uuid" if !util.FileExists(fileName) { - dirUuid, _ := uuid.NewRandom() - dirUuidString = dirUuid.String() - writeErr := util.WriteFile(fileName, []byte(dirUuidString), 0644) - if writeErr != nil { - return "", fmt.Errorf("failed to write uuid to %s : %v", fileName, writeErr) - } + dirUuidString, err = writeNewUuid(fileName) } else { uuidData, readErr := os.ReadFile(fileName) if readErr != nil { return "", fmt.Errorf("failed to read uuid from %s : %v", fileName, readErr) } - dirUuidString = string(uuidData) + if len(uuidData) > 0 { + dirUuidString = string(uuidData) + } else { + dirUuidString, err = writeNewUuid(fileName) + } + } + return dirUuidString, err +} + +func writeNewUuid(fileName string) (string, error) { + dirUuid, _ := uuid.NewRandom() + dirUuidString := dirUuid.String() + if err := util.WriteFile(fileName, []byte(dirUuidString), 0644); err != nil { + return "", fmt.Errorf("failed to write uuid to %s : %v", fileName, err) } return dirUuidString, nil } |
