diff --git a/service/store/store.go b/service/store/store.go index 59fdb87..c63e2d7 100644 --- a/service/store/store.go +++ b/service/store/store.go @@ -694,7 +694,7 @@ func (s *Store) GC(discardOrphanDealsAfter time.Duration) (bidsRemoved, filesRem if _, exists := removeFiles[path]; exists { shouldRemove = true } else if _, exists := keepFiles[path]; !exists { - if time.Since(info.ModTime()) > discardOrphanDealsAfter { + if discardOrphanDealsAfter > 0 && time.Since(info.ModTime()) > discardOrphanDealsAfter { shouldRemove = true } } diff --git a/service/store/store_test.go b/service/store/store_test.go index 9de8673..49dae4f 100644 --- a/service/store/store_test.go +++ b/service/store/store_test.go @@ -226,6 +226,12 @@ func TestStore_GC(t *testing.T) { require.NoError(t, err) _ = f.Close() + manualFile := s.dealDataFilePathFor("", failBid.PayloadCid.String()) + // simulate manually downloaded file + f, err = os.Create(manualFile) + require.NoError(t, err) + _ = f.Close() + hangingBid, _ = s.GetBid(hangingBid.ID) assert.Equal(t, BidStatusAwaitingProposal, hangingBid.Status) @@ -235,14 +241,19 @@ func TestStore_GC(t *testing.T) { require.True(t, os.IsNotExist(err), "file for finalized deal should have been removed") _, err = os.Stat(failFile) require.NoError(t, err, "file for errored deal should always be kept") + _, err = os.Stat(manualFile) + require.NoError(t, err, "manually downloaded file should have been kept") + _, err = s.GetBid(hangingBid.ID) require.NoError(t, err, "not cleaning orphan deals") // GC with discarding orphan deals - s.GC(time.Second) + time.Sleep(100 * time.Millisecond) + s.GC(100 * time.Millisecond) _, err = os.Stat(failFile) require.NoError(t, err, "file for errored deal should always be kept") - // + _, err = os.Stat(manualFile) + require.Error(t, err, "manually downloaded file should be discarded") _, err = s.GetBid(hangingBid.ID) require.Equal(t, ErrBidNotFound, err, "orphan deals should have been cleaned up") }