From 4155ef280867a6ccfe94d6f89cee4662ab24898f Mon Sep 17 00:00:00 2001 From: "Roger D. Peng [audrey]" Date: Tue, 19 Aug 2008 09:33:43 -0400 Subject: [PATCH] Add a 'tryCatch' when modifying 'map0' in 'checkMap' When there is a size change, we modify 'map' directly via the 'read_key_map' function. But if there is an error at the C level then 'map' is left in an inconsistent state. Therefore, in case of an error we just return the original map (before modification). --- R/filehash-DB1.R | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/R/filehash-DB1.R b/R/filehash-DB1.R index 3d4e72a..4e79959 100644 --- a/R/filehash-DB1.R +++ b/R/filehash-DB1.R @@ -196,7 +196,7 @@ deleteLockFile <- function(name) { TRUE } -###################################################################### +################################################################################ ## Internal utilities filesize <- gotoEndPos @@ -212,15 +212,23 @@ setMethod("checkMap", "filehashDB1", old.size }) size.change <- old.size != cur.size - map.orig <- getMap(db) - - map <- if(is.null(map.orig)) - readKeyMap(filecon) - else if(size.change) - readKeyMap(filecon, map.orig, old.size) + map <- getMap(db) + map0 <- map + + if(is.null(map)) + map <- readKeyMap(filecon) + else if(size.change) { + ## Modify 'map.old' directly + map <- tryCatch({ + readKeyMap(filecon, map, old.size) + }, error = function(err) { + message(conditionMessage(err)) + map0 + }) + } else - map.orig - if(!identical(map, map.orig)) { + map <- map0 + if(!identical(map, map0)) { db@meta$updatemap(map) db@meta$updatesize(cur.size) } -- 2.11.4.GIT