Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions src/DataBlobs/services/BlobStores.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ end

function getBlob(store::FolderStore{T}, blobId::UUID) where {T}
blobfilename = joinpath(store.folder, string(store.label), string(blobId))
if isfile(blobfilename)
tombstonefile = blobfilename * ".deleted"
if isfile(tombstonefile)
throw(IdNotFoundError("Blob (deleted)", blobId))
elseif isfile(blobfilename)
open(blobfilename) do f
return read(f)
end
Expand All @@ -164,24 +167,28 @@ function addBlob!(store::FolderStore{T}, blobId::UUID, data::T) where {T}
end

function updateBlob!(store::FolderStore{T}, blobId::UUID, data::T) where {T}
blobfilename = joinpath(store.folder, string(store.label), string(blobId))
if !isfile(blobfilename)
@warn "Key '$blobId' doesn't exist."
else
open(blobfilename, "w") do f
return write(f, data)
end
return data
end
return error("updateBlob! is obsolete as blobsId=>Blob pairs are immutable.")
end

function deleteBlob!(store::FolderStore{T}, blobId::UUID) where {T}
# Tombstone pattern: instead of deleting the file, create a tombstone marker file
blobfilename = joinpath(store.folder, string(store.label), string(blobId))
if !isfile(blobfilename)
tombstonefile = blobfilename * ".deleted"
if isfile(blobfilename)
# Remove the actual blob file
rm(blobfilename)
# Create a tombstone marker
open(tombstonefile, "w") do f
return write(f, "deleted")
end
return 1
elseif isfile(tombstonefile)
# Already deleted
return 0
else
# Not found
throw(IdNotFoundError("Blob", blobId))
end
rm(blobfilename)
return 1
end

function hasBlob(store::FolderStore, blobId::UUID)
Expand All @@ -191,7 +198,15 @@ end

hasBlob(store::FolderStore, entry::Blobentry) = hasBlob(store, entry.blobId)

listBlobs(store::FolderStore) = readdir(store.folder)
function listBlobs(store::FolderStore)
folder = joinpath(store.folder, string(store.label))
# Parse folder to only include UUIDs automatically excluding tombstone files this way.
blobIds = map(readdir(folder)) do filename
return tryparse(UUID, filename)
end
return filter(!isnothing, blobIds)
end

##==============================================================================
## InMemoryBlobstore
##==============================================================================
Expand Down
Loading