issue5097 - need to handle an existing directory entry present in the cache from older apptainer versions.
(t *testing.T)
| 24 | // issue5097 - need to handle an existing directory entry present in the cache |
| 25 | // from older apptainer versions. |
| 26 | func (c cacheTests) issue5097(t *testing.T) { |
| 27 | imgCacheDir, cleanCache := e2e.MakeCacheDir(t, c.env.TestDir) |
| 28 | defer cleanCache(t) |
| 29 | c.env.UnprivCacheDir = imgCacheDir |
| 30 | |
| 31 | tempDir, imgStoreCleanup := e2e.MakeTempDir(t, "", "", "image store") |
| 32 | defer imgStoreCleanup(t) |
| 33 | imagePath := filepath.Join(tempDir, imgName) |
| 34 | |
| 35 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 36 | http.ServeFile(w, r, c.env.ImagePath) |
| 37 | })) |
| 38 | defer srv.Close() |
| 39 | |
| 40 | // Pull through the cache - will give us a new style file in the cache |
| 41 | c.env.RunApptainer( |
| 42 | t, |
| 43 | e2e.WithProfile(e2e.UserProfile), |
| 44 | e2e.WithCommand("pull"), |
| 45 | e2e.WithArgs([]string{"--force", imagePath, srv.URL}...), |
| 46 | e2e.ExpectExit(0), |
| 47 | ) |
| 48 | |
| 49 | // Replace the cache entry with a directory, containing the image, |
| 50 | // like in older versions of apptainer |
| 51 | hash, err := netHash(srv.URL) |
| 52 | if err != nil { |
| 53 | t.Fatalf("Could not calculate hash of test image: %v", err) |
| 54 | } |
| 55 | cachePath := path.Join(imgCacheDir, "cache", "net", hash) |
| 56 | err = os.Remove(cachePath) |
| 57 | if err != nil { |
| 58 | t.Fatalf("Could not remove cached image '%s': %v", cachePath, err) |
| 59 | } |
| 60 | err = os.Mkdir(cachePath, 0o700) |
| 61 | if err != nil { |
| 62 | t.Fatalf("Could not create directory '%s': %v", cachePath, err) |
| 63 | } |
| 64 | err = fs.CopyFile(imagePath, path.Join(cachePath, hash), 0o700) |
| 65 | if err != nil { |
| 66 | t.Fatalf("Could not copy file to directory '%s': %v", cachePath, err) |
| 67 | } |
| 68 | |
| 69 | // Pull through the cache - it should work as we now remove the directory and |
| 70 | // re-pull a file into the cache |
| 71 | c.env.RunApptainer( |
| 72 | t, |
| 73 | e2e.WithProfile(e2e.UserProfile), |
| 74 | e2e.WithCommand("pull"), |
| 75 | e2e.WithArgs([]string{"--force", imagePath, srv.URL}...), |
| 76 | e2e.ExpectExit(0), |
| 77 | ) |
| 78 | |
| 79 | if !fs.IsFile(cachePath) { |
| 80 | t.Fatalf("Cache entry '%s' is not a file", cachePath) |
| 81 | } |
| 82 | } |
| 83 |
nothing calls this directly
no test coverage detected