0da789cd96
Migration 0002 added fsid column with DEFAULT 0 but never populated existing rows. Now PopulateLegacyFSIDs() runs after 0002 to extract fsid from legacy options string or generate random. Also: move generateRandomFSID to internal/system to avoid import cycles. Migration 0004 drops the legacy options column. Version: 0.3.1 -> 0.3.2
21 lines
365 B
Go
21 lines
365 B
Go
package nfs
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/darroyo/nasctl/internal/system"
|
|
)
|
|
|
|
func UniqueFSID(used map[uint32]struct{}) (uint32, error) {
|
|
for i := 0; i < 64; i++ {
|
|
n, err := system.GenerateRandomFSID()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
if _, dup := used[n]; !dup {
|
|
return n, nil
|
|
}
|
|
}
|
|
return 0, fmt.Errorf("fsid space exhausted after 64 attempts")
|
|
}
|