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
20 lines
304 B
Go
20 lines
304 B
Go
package system
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/binary"
|
|
"fmt"
|
|
)
|
|
|
|
func GenerateRandomFSID() (uint32, error) {
|
|
var b [4]byte
|
|
if _, err := rand.Read(b[:]); err != nil {
|
|
return 0, fmt.Errorf("crypto/rand read: %w", err)
|
|
}
|
|
n := binary.BigEndian.Uint32(b[:])
|
|
if n == 0 {
|
|
n = 1
|
|
}
|
|
return n, nil
|
|
}
|