Handle both types of root directory

andybalholm
Apr 7, 2023, 6:07 PM
KMLCXD5DQPRT43PFRMVWYPQRZUNW6OR3PI4NKA6G4EAFHTPXV5KAC

Dependencies

Change contents

  • edit in pristine.go at line 72
    [5.592]
    [3.1044]
    if change == (Hash{}) {
    return g.Root
    }
  • replacement in pristine.go at line 254
    [2.303][2.303:316](),[2.316][2.316:427]()
    b := g.Root
    for i := 0; i < 2; i++ {
    var next *Block
    for _, e := range b.Edges {
    if e.Flag&EdgeFlagsDeleted != 0 {
    [2.303]
    [2.427]
    // There are two possible configurations for the directory structure:
    // The old setup had directory entries as direct children of the root.
    // The new setup has a special root inode, which is a child of an intermediate
    // vertex, which is a child of the root.
    //
    // So we need to try both possibilities.
    var possibleRoots []*Block
    var directFiles []*Block
    for _, e := range g.Root.Edges {
    if e.Flag&EdgeFlagsDeleted != 0 {
    continue
    }
    if e.Flag&EdgeFlagsFolder == 0 {
    return nil, errors.New("non-folder edge found while looking for root directory")
    }
    b := e.To
    if len(b.Content) > 0 {
    directFiles = append(directFiles, b)
    continue
    }
    for _, f := range b.Edges {
    if f.Flag&EdgeFlagsDeleted != 0 {
  • replacement in pristine.go at line 278
    [2.445][2.445:481]()
    if e.Flag&EdgeFlagsFolder == 0 {
    [2.445]
    [2.481]
    if f.Flag&EdgeFlagsFolder == 0 {
  • replacement in pristine.go at line 281
    [2.571][2.571:595]()
    next = e.To
    break
    [2.571]
    [2.595]
    if len(f.To.Content) > 0 {
    continue
    }
    possibleRoots = append(possibleRoots, f.To)
  • edit in pristine.go at line 286
    [2.599][2.599:686]()
    if next == nil {
    return nil, errors.New("no root directory found")
    }
    b = next
  • replacement in pristine.go at line 288
    [2.690][2.690:705]()
    return b, nil
    [2.690]
    [3.3352]
    if len(directFiles) > 0 || len(possibleRoots) == 0 {
    return g.Root, nil
    }
    if len(possibleRoots) > 1 {
    return nil, fmt.Errorf("found %d possible root directories", len(possibleRoots))
    }
    return possibleRoots[0], nil