Skip to content

Commit

Permalink
Remove all existing (potentially obsolete) ..links files during reind…
Browse files Browse the repository at this point in the history
…exing.
  • Loading branch information
LTLA committed Jan 27, 2025
1 parent b94c02d commit e273e5c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,12 @@ func reindexDirectory(registry, project, asset, version string) error {
if info.IsDir() {
return filepath.SkipDir
} else {
if base == linksFileName {
err := os.Remove(src_path)
if err != nil {
return fmt.Errorf("failed to remove old ..links file at %q; %w", src_path, err)
}
}
return nil
}
}
Expand Down
36 changes: 36 additions & 0 deletions transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,31 @@ func TestReindexDirectorySimple(t *testing.T) {
if err != nil {
t.Fatal(err)
}

// What happens if we inject a ..links file in there?
lpath := filepath.Join(v_path, linksFileName)
err = os.WriteFile(lpath, []byte{}, 0644)
if err != nil {
t.Fatal(err)
}

lpath2 := filepath.Join(v_path, "moves", "electric", linksFileName)
err = os.WriteFile(lpath2, []byte{}, 0644)
if err != nil {
t.Fatal(err)
}

err = reindexDirectory(reg, project, asset, version)
if err != nil {
t.Fatalf("failed to reindex directory; %v", err)
}

if _, err := os.Stat(lpath); err == nil || !errors.Is(err, os.ErrNotExist) {
t.Error("expected existing ..links file to be deleted")
}
if _, err := os.Stat(lpath2); err == nil || !errors.Is(err, os.ErrNotExist) {
t.Error("expected existing nested ..links file to be deleted")
}
}

func TestReindexDirectorySkipHidden(t *testing.T) {
Expand Down Expand Up @@ -1314,6 +1339,17 @@ func TestReindexDirectoryRegistryLinks(t *testing.T) {
if err != nil {
t.Fatal(err)
}

// Confirming that we have ..links files.
_, found := recovered[linksFileName]
if !found {
t.Error("missing a top-level ..links file")
}

_, found = recovered[filepath.Join("moves", "electric", linksFileName)]
if !found {
t.Error("missing a nested ..links file")
}
}

func TestReindexDirectoryRegistryLinkFailures(t *testing.T) {
Expand Down

0 comments on commit e273e5c

Please sign in to comment.