@@ -259,10 +259,21 @@ REV_load_annotation_info <- function(folder_contents, review, dataset_lists) {
259259
260260 base_timestamp <- NA_real_
261261 data_timestamps_st <- rep(NA_real_ , row_count )
262- # <domain>_000.base
263- file_path <- file.path(dataset_lists_name , paste0(dataset_review_name , " _000.base" ))
264- if (file_path %in% names(folder_contents )) {
265- contents <- folder_contents [[file_path ]]
262+
263+ # <domain>_0000.base
264+ # - Older versions of the review functionality devoted three digits to the `.base` and `.delta` sequence numbers.
265+ # The current version uses four digits. Here we detect the one that was used for this particular domain (if it
266+ # exists) and use it for the associated delta files.
267+ base_file_path_pattern <- sprintf(" ^%s_0+.base$" , file.path(dataset_lists_name , dataset_review_name ))
268+ base_file_path <- grep(base_file_path_pattern , names(folder_contents ), value = TRUE )
269+ if (length(base_file_path ) > 1L ) {
270+ error <- c(error , paste0(" [" , dataset_review_name , " ] " , " Multiple `.base` files found:\n " ,
271+ paste(sprintf(" `%s`" , base_file_path ), collapse = " , " ), " .\n " ))
272+ base_file_path <- sort(base_file_path )[[1 ]]
273+ }
274+
275+ if (length(base_file_path ) == 1 ) { # existing `.base` file
276+ contents <- folder_contents [[base_file_path ]]
266277
267278 sorted_delta_file_paths <- local({
268279 pattern <- sprintf(" ^%s_[0-9]*.delta" , file.path(dataset_lists_name , dataset_review_name ))
@@ -383,18 +394,22 @@ REV_load_annotation_info <- function(folder_contents, review, dataset_lists) {
383394 base_info <- RS_load(contents , deltas )
384395
385396 delta_number <- length(sorted_delta_file_paths ) + 1
386- file_path <- file.path(dataset_lists_name , sprintf(" %s_%03d.delta" , dataset_review_name , delta_number ))
397+ revision_digit_count <- nchar(sub(" .*_(0+)\\ .base$" , " \\ 1" , base_file_path ))
398+ file_path <- file.path(
399+ dataset_lists_name , sprintf(" %s_%.*d.delta" , dataset_review_name , revision_digit_count , delta_number )
400+ )
387401 append_IO_action(list (kind = " write" , path = file_path , contents = new_delta_contents , offset = 0L ))
388402 }
389403 }
390- } else {
404+ } else { # new `.base` file
405+ base_file_path <- file.path(dataset_lists_name , paste0(dataset_review_name , " _0000.base" ))
391406 contents <- RS_compute_base_memory(dataset_review_name , dataset , id_vars , tracked_vars )
392407 if (inherits(contents , " simpleCondition" )) {
393408 # IMPORTANT: Not being able to compute the base info is too severe an error to recover from, so we error out
394409 return (list (error = c(error , contents [[" message" ]])))
395410 } else {
396411 base_info <- RS_load(base = contents , deltas = list ())
397- append_IO_action(list (kind = " write" , path = file_path , contents = contents , offset = 0L ))
412+ append_IO_action(list (kind = " write" , path = base_file_path , contents = contents , offset = 0L ))
398413 }
399414 }
400415
0 commit comments