Skip to content

Commit

Permalink
Merge pull request #584 from JuliaRobotics/maint/20Q3/mkfile#580
Browse files Browse the repository at this point in the history
Make directory if it doesn't exist with @info
  • Loading branch information
Affie authored Aug 9, 2020
2 parents d1f3c41 + 084fdc8 commit 91665b3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/DataBlobs/services/BlobStores.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,18 @@ export FolderStore
struct FolderStore{T} <: AbstractBlobStore{T}
key::Symbol
folder::String
function FolderStore{T}(key, folder) where T
if !isdir(folder)
@info "Folder '$folder' doesn't exist - creating."
# create new folder
mkpath(folder)
end
return new(key, folder)
end
end

FolderStore(foldername::String) = FolderStore{Vector{UInt8}}(:default_folder_store, foldername)

blobfilename(store::FolderStore, entry::BlobStoreEntry) = joinpath(store.folder,"$(entry.id).dat")
entryfilename(store::FolderStore, entry::BlobStoreEntry) = joinpath(store.folder,"$(entry.id).json")

Expand Down
4 changes: 2 additions & 2 deletions src/DataBlobs/services/FileDataEntryBlob.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ struct FileDataEntry <: AbstractDataEntry

function FileDataEntry(label, id, folder, hash, timestamp)
if !isdir(folder)
@warn "Folder '$folder' doesn't exist - creating."
@info "Folder '$folder' doesn't exist - creating."
# create new folder
mkpath(folder)
end
return new(label, id, folder, hash, timestamp)
end
end
end

# @generated function ==(x::FileDataEntry, y::FileDataEntry)
Expand Down
4 changes: 2 additions & 2 deletions test/consol_DataEntryBlobTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ deleteData!(dfg, :x2, :random)
##==============================================================================
## FileDataEntry
##==============================================================================
ade,adb = addData!(FileDataEntry, dfg, :x1, :random, "/tmp/dfgFilestore", dataset1)
ade,adb = addData!(FileDataEntry, dfg, :x1, :random, "/tmp/dfgFileEntryBlob", dataset1)
gde,gdb = getData(dfg, :x1, :random)
dde,ddb = deleteData!(dfg, :x1, :random)

Expand All @@ -73,7 +73,7 @@ deleteData!(dfg, :x2, :random)
##==============================================================================

# Create a data store and add it to DFG
ds = FolderStore{Vector{UInt8}}(:filestore, "/tmp/dfgFilestore")
ds = FolderStore{Vector{UInt8}}(:filestore, "/tmp/dfgFolderStore")
addBlobStore!(dfg, ds)

ade,adb = addData!(dfg, :filestore, :x1, :random, dataset1)
Expand Down

0 comments on commit 91665b3

Please sign in to comment.