# Errors if the containing directory does not exist.
locate dir=bar marker=foo
----
open bar/: file does not exist

mkdir-all data
----

read dir=data marker=foo
----

# Loads a nonexistent marker correctly.
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
----

# Moving the marker for the first time should create a marker file.
move dir=data marker=foo
MANIFEST-000010
----

list data
----
marker.foo.000001.MANIFEST-000010

next-iter  dir=data marker=foo
----
2

read dir=data marker=foo
----
MANIFEST-000010

# 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

read dir=data marker=foo
----
MANIFEST-000016

# Create non-marker files.
touch
data/MANIFEST-000016
data/CURRENT
data/000004.sst
----

# Re-locate the marker. It should be unchanged.
locate dir=data marker=foo
----
MANIFEST-000016

# Locate a new marker.
locate dir=data marker=bar
----

move dir=data marker=bar
MANIFEST-000016
----

list data
----
000004.sst
CURRENT
MANIFEST-000016
marker.bar.000001.MANIFEST-000016
marker.foo.000002.MANIFEST-000016

move dir=data marker=foo
MANIFEST-000021
----

list data
----
000004.sst
CURRENT
MANIFEST-000016
marker.bar.000001.MANIFEST-000016
marker.foo.000003.MANIFEST-000021

touch
data/marker.bar.000009.MANIFEST-000099
----

list data
----
000004.sst
CURRENT
MANIFEST-000016
marker.bar.000001.MANIFEST-000016
marker.bar.000009.MANIFEST-000099
marker.foo.000003.MANIFEST-000021

locate dir=data marker=bar
----
MANIFEST-000099

remove-obsolete dir=data marker=bar
----
Removed 1 files.

list data
----
000004.sst
CURRENT
MANIFEST-000016
marker.bar.000009.MANIFEST-000099
marker.foo.000003.MANIFEST-000021

read dir=data marker=bar
----
MANIFEST-000099

read dir=data marker=garbage
----
