Skip to content

Commit e273e5c

Browse files
committed
Remove all existing (potentially obsolete) ..links files during reindexing.
1 parent b94c02d commit e273e5c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

transfer.go

+6
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,12 @@ func reindexDirectory(registry, project, asset, version string) error {
541541
if info.IsDir() {
542542
return filepath.SkipDir
543543
} else {
544+
if base == linksFileName {
545+
err := os.Remove(src_path)
546+
if err != nil {
547+
return fmt.Errorf("failed to remove old ..links file at %q; %w", src_path, err)
548+
}
549+
}
544550
return nil
545551
}
546552
}

transfer_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,31 @@ func TestReindexDirectorySimple(t *testing.T) {
11561156
if err != nil {
11571157
t.Fatal(err)
11581158
}
1159+
1160+
// What happens if we inject a ..links file in there?
1161+
lpath := filepath.Join(v_path, linksFileName)
1162+
err = os.WriteFile(lpath, []byte{}, 0644)
1163+
if err != nil {
1164+
t.Fatal(err)
1165+
}
1166+
1167+
lpath2 := filepath.Join(v_path, "moves", "electric", linksFileName)
1168+
err = os.WriteFile(lpath2, []byte{}, 0644)
1169+
if err != nil {
1170+
t.Fatal(err)
1171+
}
1172+
1173+
err = reindexDirectory(reg, project, asset, version)
1174+
if err != nil {
1175+
t.Fatalf("failed to reindex directory; %v", err)
1176+
}
1177+
1178+
if _, err := os.Stat(lpath); err == nil || !errors.Is(err, os.ErrNotExist) {
1179+
t.Error("expected existing ..links file to be deleted")
1180+
}
1181+
if _, err := os.Stat(lpath2); err == nil || !errors.Is(err, os.ErrNotExist) {
1182+
t.Error("expected existing nested ..links file to be deleted")
1183+
}
11591184
}
11601185

11611186
func TestReindexDirectorySkipHidden(t *testing.T) {
@@ -1314,6 +1339,17 @@ func TestReindexDirectoryRegistryLinks(t *testing.T) {
13141339
if err != nil {
13151340
t.Fatal(err)
13161341
}
1342+
1343+
// Confirming that we have ..links files.
1344+
_, found := recovered[linksFileName]
1345+
if !found {
1346+
t.Error("missing a top-level ..links file")
1347+
}
1348+
1349+
_, found = recovered[filepath.Join("moves", "electric", linksFileName)]
1350+
if !found {
1351+
t.Error("missing a nested ..links file")
1352+
}
13171353
}
13181354

13191355
func TestReindexDirectoryRegistryLinkFailures(t *testing.T) {

0 commit comments

Comments
 (0)