diff --git a/vfs/atomicfs/marker.go b/vfs/atomicfs/marker.go index 99bf60243c..22bbd554a0 100644 --- a/vfs/atomicfs/marker.go +++ b/vfs/atomicfs/marker.go @@ -2,7 +2,7 @@ // of this source code is governed by a BSD-style license that can be found in // the LICENSE file. -package vfs +package atomicfs import ( "fmt" @@ -195,6 +195,13 @@ func (a *Marker) Move(filename string) error { return nil } +// NextIter returns the next iteration number that the marker will use. +// Clients may use this number for formulating filenames that are +// unused. +func (a *Marker) NextIter() uint64 { + return a.iter + 1 +} + // RemoveObsolete removes any obsolete files discovered while locating // the marker or files unable to be removed during Move. func (a *Marker) RemoveObsolete() error { diff --git a/vfs/atomicfs/marker_test.go b/vfs/atomicfs/marker_test.go index 37d03f02bb..5668d25394 100644 --- a/vfs/atomicfs/marker_test.go +++ b/vfs/atomicfs/marker_test.go @@ -2,7 +2,7 @@ // of this source code is governed by a BSD-style license that can be found in // the LICENSE file. -package vfs +package atomicfs import ( "bytes" @@ -117,6 +117,14 @@ func TestMarker(t *testing.T) { } return "" + case "next-iter": + var dir, marker string + td.ScanArgs(t, "dir", &dir) + td.ScanArgs(t, "marker", &marker) + m := markers[memFS.PathJoin(dir, marker)] + require.NotNil(t, m) + return fmt.Sprintf("%d", m.NextIter()) + case "remove-obsolete": var dir, marker string td.ScanArgs(t, "dir", &dir) diff --git a/vfs/atomicfs/testdata/marker b/vfs/atomicfs/testdata/marker index ffb7a7a71a..2450bd24bf 100644 --- a/vfs/atomicfs/testdata/marker +++ b/vfs/atomicfs/testdata/marker @@ -10,6 +10,14 @@ mkdir-all data locate dir=data marker=foo ---- +next-iter dir=data marker=foo +---- +1 + +next-iter dir=data marker=foo +---- +1 + # The directory should still be empty. list data ---- @@ -23,11 +31,19 @@ list data ---- marker.foo.000001.MANIFEST-000010 +next-iter dir=data marker=foo +---- +2 + # Moving the marker should move the existing marker file. move dir=data marker=foo MANIFEST-000016 ---- +next-iter dir=data marker=foo +---- +3 + list data ---- marker.foo.000002.MANIFEST-000016