7676# also creates an blobid as uuid4
7777addBlob! (store:: AbstractBlobstore , data) = addBlob! (store, uuid4 (), data)
7878
79- # update
80- function updateBlob! (dfg:: AbstractDFG , entry:: Blobentry , data)
81- return updateBlob! (getBlobstore (dfg, entry. blobstore), entry. blobid, data)
82- end
83-
84- function updateBlob! (store:: AbstractBlobstore , entry:: Blobentry , data)
85- return updateBlob! (store, entry. blobid, data)
86- end
8779# delete
8880function deleteBlob! (dfg:: AbstractDFG , entry:: Blobentry )
8981 return deleteBlob! (getBlobstore (dfg, entry. blobstore), entry)
147139
148140function getBlob (store:: FolderStore{T} , blobid:: UUID ) where {T}
149141 blobfilename = joinpath (store. folder, string (store. label), string (blobid))
150- if isfile (blobfilename)
142+ tombstonefile = blobfilename * " .deleted"
143+ if isfile (tombstonefile)
144+ throw (IdNotFoundError (" Blob (deleted)" , blobid))
145+ elseif isfile (blobfilename)
151146 open (blobfilename) do f
152147 return read (f)
153148 end
@@ -168,25 +163,25 @@ function addBlob!(store::FolderStore{T}, blobid::UUID, data::T) where {T}
168163 end
169164end
170165
171- function updateBlob! (store:: FolderStore{T} , blobid:: UUID , data:: T ) where {T}
172- blobfilename = joinpath (store. folder, string (store. label), string (blobid))
173- if ! isfile (blobfilename)
174- @warn " Key '$blobid ' doesn't exist."
175- else
176- open (blobfilename, " w" ) do f
177- return write (f, data)
178- end
179- return data
180- end
181- end
182-
183166function deleteBlob! (store:: FolderStore{T} , blobid:: UUID ) where {T}
167+ # Tombstone pattern: instead of deleting the file, create a tombstone marker file
184168 blobfilename = joinpath (store. folder, string (store. label), string (blobid))
185- if ! isfile (blobfilename)
169+ tombstonefile = blobfilename * " .deleted"
170+ if isfile (blobfilename)
171+ # Remove the actual blob file
172+ rm (blobfilename)
173+ # Create a tombstone marker
174+ open (tombstonefile, " w" ) do f
175+ return write (f, " deleted" )
176+ end
177+ return 1
178+ elseif isfile (tombstonefile)
179+ # Already deleted
180+ return 0
181+ else
182+ # Not found
186183 throw (IdNotFoundError (" Blob" , blobid))
187184 end
188- rm (blobfilename)
189- return 1
190185end
191186
192187function hasBlob (store:: FolderStore , blobid:: UUID )
196191
197192hasBlob (store:: FolderStore , entry:: Blobentry ) = hasBlob (store, entry. blobid)
198193
199- listBlobs (store:: FolderStore ) = readdir (store. folder)
194+ function listBlobs (store:: FolderStore )
195+ folder = joinpath (store. folder, string (store. label))
196+ # Parse folder to only include UUIDs automatically excluding tombstone files this way.
197+ blobids = UUID[]
198+ for filename in readdir (folder)
199+ id = tryparse (UUID, filename)
200+ isnothing (id) && continue
201+ push! (blobids, id)
202+ end
203+ return blobids
204+ end
205+
200206# #==============================================================================
201207# # InMemoryBlobstore
202208# #==============================================================================
@@ -228,13 +234,6 @@ function addBlob!(store::InMemoryBlobstore{T}, blobid::UUID, data::T) where {T}
228234 return blobid
229235end
230236
231- function updateBlob! (store:: InMemoryBlobstore{T} , blobid:: UUID , data:: T ) where {T}
232- if haskey (store. blobs, blobid)
233- @warn " Key '$blobid ' doesn't exist."
234- end
235- return store. blobs[blobid] = data
236- end
237-
238237function deleteBlob! (store:: InMemoryBlobstore , blobid:: UUID )
239238 if ! haskey (store. blobs, blobid)
240239 throw (IdNotFoundError (" Blob" , blobid))
0 commit comments