Skip to content

Commit cadd02c

Browse files
committed
Extend the posixfs consistency command to fix name attr mismatches
1 parent 3df5eb9 commit cadd02c

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

opencloud/pkg/command/posixfs.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
const (
3232
parentIDAttrName = "user.oc.parentid"
3333
idAttrName = "user.oc.id"
34+
nameAttrName = "user.oc.name"
3435
spaceIDAttrName = "user.oc.space.id"
3536
ownerIDAttrName = "user.oc.owner.id"
3637
)
@@ -292,7 +293,7 @@ func checkSpaceID(spacePath string) {
292293
}
293294
}
294295

295-
func walkParentIDs(dir string, parentID string) int {
296+
func walkNodes(dir string, parentID string) int {
296297
fixes := 0
297298
entries, err := os.ReadDir(dir)
298299
if err != nil {
@@ -307,14 +308,30 @@ func walkParentIDs(dir string, parentID string) int {
307308
continue
308309
}
309310

311+
// Check if the parent ID attribute matches the expected parent ID, if not, fix it.
310312
actualParentID, err := xattr.Get(fullPath, parentIDAttrName)
311313
if err != nil || string(actualParentID) != parentID {
312314
err = xattr.Set(fullPath, parentIDAttrName, []byte(parentID))
313315
if err != nil {
314316
logFailure("Failed to fix parent ID for '%s': %v", fullPath, err)
315317
} else {
316318
spinner.Pause()
317-
fmt.Printf("\n + Fixed parent ID for '%s'\n", fullPath)
319+
fmt.Printf(" + Fixed parent ID for '%s'", fullPath)
320+
spinner.Unpause()
321+
fixes++
322+
restartRequired = true
323+
}
324+
}
325+
326+
// Check that the name attribute matches the actual name of the file/directory, if not, fix it.
327+
nameAttr, err := xattr.Get(fullPath, nameAttrName)
328+
if err != nil || string(nameAttr) != entry.Name() {
329+
err = xattr.Set(fullPath, nameAttrName, []byte(entry.Name()))
330+
if err != nil {
331+
logFailure("Failed to fix name attribute for '%s': %v", fullPath, err)
332+
} else {
333+
spinner.Pause()
334+
fmt.Printf(" + Fixed name attribute for '%s'", fullPath)
318335
spinner.Unpause()
319336
fixes++
320337
restartRequired = true
@@ -327,26 +344,26 @@ func walkParentIDs(dir string, parentID string) int {
327344
logFailure("Directory '%s' missing '%s', skipping its children", fullPath, idAttrName)
328345
continue
329346
}
330-
walkParentIDs(fullPath, string(nodeID))
347+
walkNodes(fullPath, string(nodeID))
331348
}
332349
}
333350
return fixes
334351
}
335352

336353
func checkNodeIDs(spacePath string) {
337-
spinner.Message(" - checking parent IDs")
354+
spinner.Message(" - checking nodes")
338355

339356
rootID, err := xattr.Get(spacePath, idAttrName)
340357
if err != nil || len(rootID) == 0 {
341358
logFailure("Space root '%s' missing '%s' attribute", spacePath, idAttrName)
342359
return
343360
}
344361

345-
fixes := walkParentIDs(spacePath, string(rootID))
362+
fixes := walkNodes(spacePath, string(rootID))
346363

347364
if fixes > 0 {
348365
spinner.Pause()
349-
fmt.Printf("\n ✓ Fixed %d incorrect parent IDs in %s\n", fixes, filepath.Base(spacePath))
366+
fmt.Printf("\n ✓ Fixed %d incorrect node attributes in %s\n", fixes, filepath.Base(spacePath))
350367
spinner.Unpause()
351368
}
352369
}

0 commit comments

Comments
 (0)