@@ -255,6 +255,40 @@ function local_data_abspath(::Nothing, path)
255
255
end
256
256
257
257
258
+ # Return local filesystem absolute path for the dataset, as a string
259
+ function _filesystem_dataset_abspath (dataset)
260
+ config = dataset. storage
261
+ if haskey (config, " path" )
262
+ pathstr = config[" path" ]
263
+ # Local absolute paths are not portable. Previously these were allowed
264
+ # in the "path" key, but those are now deprecated in favor of
265
+ # system-specific path keys unix_path or windows_path
266
+ if isabspath (pathstr)
267
+ Base. depwarn ("""
268
+ Absolute paths in Data.toml are deprecated. Instead, use relative
269
+ paths (separated with `/`) relative to the Data.toml location.""" ,
270
+ :connect_filesystem )
271
+ return pathstr
272
+ else
273
+ if ' \\ ' in pathstr && Sys. iswindows ()
274
+ # Heuristic deprecation warning for windows paths in Data.toml
275
+ Base. depwarn (
276
+ " Relative paths in Data.toml should be separated with '/' characters." ,
277
+ :connect_filesystem )
278
+ pathstr = join (split (pathstr, ' \\ ' ), ' /' )
279
+ end
280
+ relpath = joinpath (split (pathstr, ' /' )... )
281
+ return local_data_abspath (data_project (dataset), relpath)
282
+ end
283
+ elseif haskey (config, " unix_path" ) && Sys. isunix ()
284
+ return config[" unix_path" ]
285
+ elseif haskey (config, " windows_path" ) && Sys. iswindows ()
286
+ return config[" windows_path" ]
287
+ else
288
+ error (" No \" path\" key found for FileSystem storage driver." )
289
+ end
290
+ end
291
+
258
292
"""
259
293
## Metadata spec
260
294
@@ -284,40 +318,12 @@ For FileTree:
284
318
function open_dataset (driver:: FileSystemDriver , dataset, write)
285
319
config = dataset. storage
286
320
# Paths keys can be in three forms documented above;
287
- if haskey (config, " path" )
288
- pathstr = config[" path" ]
289
- # Local absolute paths are not portable. Previously these were allowed
290
- # in the "path" key, but those are now deprecated in favor of
291
- # system-specific path keys unix_path or windows_path
292
- if isabspath (pathstr)
293
- Base. depwarn ("""
294
- Absolute paths in Data.toml are deprecated. Instead, use relative
295
- paths (separated with `/`) relative to the Data.toml location.""" ,
296
- :connect_filesystem )
297
- path = pathstr
298
- else
299
- if ' \\ ' in pathstr && Sys. iswindows ()
300
- # Heuristic deprecation warning for windows paths in Data.toml
301
- Base. depwarn (
302
- " Relative paths in Data.toml should be separated with '/' characters." ,
303
- :connect_filesystem )
304
- pathstr = join (split (pathstr, ' \\ ' ), ' /' )
305
- end
306
- relpath = joinpath (split (pathstr, ' /' )... )
307
- path = local_data_abspath (data_project (dataset), relpath)
308
- end
309
- elseif haskey (config, " unix_path" ) && Sys. isunix ()
310
- path = config[" unix_path" ]
311
- elseif haskey (config, " windows_path" ) && Sys. iswindows ()
312
- path = config[" windows_path" ]
313
- else
314
- error (" No \" path\" key found for FileSystem storage driver." )
315
- end
316
321
type = config[" type" ]
317
- if type in (" File" , " Blob" )
322
+ path = _filesystem_dataset_abspath (dataset)
323
+ if is_File_dtype (type)
318
324
isfile (path) || throw (ArgumentError (" $(repr (path)) should be a file" ))
319
325
storage = File (FileSystemRoot (path; write= write))
320
- elseif type in ( " FileTree " , " BlobTree " )
326
+ elseif is_FileTree_dtype (type )
321
327
isdir (path) || throw (ArgumentError (" $(repr (path)) should be a directory" ))
322
328
storage = FileTree (FileSystemRoot (path; write= write))
323
329
path = dataspec_fragment_as_path (dataset)
@@ -333,59 +339,54 @@ end
333
339
function create_storage (proj, driver:: FileSystemDriver ,
334
340
name:: AbstractString ;
335
341
source:: Union{Nothing,DataSet} = nothing ,
336
- dtype :: Union{Nothing,AbstractString} = nothing ,
342
+ type :: Union{Nothing,AbstractString} = nothing ,
337
343
kws... )
338
-
339
344
# For other cases here, we're not linking to the original source, but
340
345
# rather making a copy.
341
346
if ! isnothing (source)
342
- dtype = source. storage[" type" ]
347
+ type = source. storage[" type" ]
343
348
else
344
- if isnothing (dtype )
345
- throw (ArgumentError (" Must provide one of `source` or `dtype `." ))
349
+ if isnothing (type )
350
+ throw (ArgumentError (" Must provide one of `source` or `type `." ))
346
351
end
347
352
end
348
353
349
354
has_slashes = ' /' in name
350
- local_name = has_slashes ?
351
- joinpath (split (name, ' /' )) :
352
- name
355
+ relpath = has_slashes ? joinpath (split (name, ' /' )) : name
353
356
354
- # project_root_path() will fail
355
- data_path = joinpath (project_root_path (proj), local_name)
357
+ data_path = local_data_abspath (proj, relpath)
356
358
if ispath (data_path)
357
359
error (" Local path already exists: $data_path " )
358
360
end
359
361
360
- if ! (dtype in (" Blob " , " BlobTree " ))
361
- error (" Unknown storage type for FileSystemDriver: $dtype " )
362
+ if ! (type in (" File " , " FileTree " ))
363
+ error (" Unknown storage type for FileSystemDriver: $type " )
362
364
end
363
365
364
366
# Create file or directory
365
367
if has_slashes
366
368
mkpath (dirname (data_path))
367
369
end
368
- if dtype == " Blob "
370
+ if is_File_dtype (type)
369
371
touch (data_path)
370
- elseif dtype == " BlobTree "
372
+ elseif is_FileTree_dtype (type)
371
373
mkdir (data_path)
372
374
end
373
375
374
376
Dict (
375
377
" driver" => " FileSystem" ,
376
- " type" => dtype ,
377
- " path" => " @__DIR__/ $name " ,
378
+ " type" => type ,
379
+ " path" => relpath ,
378
380
)
379
381
end
380
382
381
-
382
- function delete_storage (proj, driver:: FileSystemDriver , ds:: DataSet )
383
- path = ds. storage[" path" ]
384
- type = ds. storage[" type" ]
385
- if type == " Blob"
383
+ function delete_storage (proj, driver:: FileSystemDriver , dataset:: DataSet )
384
+ path = _filesystem_dataset_abspath (dataset)
385
+ type = dataset. storage[" type" ]
386
+ if is_File_dtype (type)
386
387
isfile (path) || throw (ArgumentError (" $(repr (path)) should be a file" ))
387
388
rm (path)
388
- elseif type == " BlobTree "
389
+ elseif is_FileTree_dtype ( type)
389
390
isdir (path) || throw (ArgumentError (" $(repr (path)) should be a directory" ))
390
391
rm (path, recursive= true )
391
392
else
@@ -394,8 +395,6 @@ function delete_storage(proj, driver::FileSystemDriver, ds::DataSet)
394
395
end
395
396
396
397
397
-
398
-
399
398
# -------------------------------------------------------------------------------
400
399
# Deprecations
401
400
function Base. abspath (relpath:: RelPath )
0 commit comments