Stub artifacts can result from several causes. The most common being erroneous removal of a file in the sqlite database. This can be caused sometimes if an archive object is being saved multiple times by multiple threads. This function will clear entries in the sqlite database which have no actual file with data.

clearStubArtifacts(repoDir = NULL)

# S4 method for ANY
clearStubArtifacts(repoDir = NULL)

Arguments

repoDir

A character denoting an existing directory of the repository for which metadata will be returned. If NULL (default), it will use the repoDir specified in archivist::setLocalRepo.

Value

Invoked for its side effect on the repoDir.

Examples

tmpDir <- file.path(tempdir(), "reproducible_examples", "clearStubArtifacts") lapply(c(runif, rnorm), function(f) { reproducible::Cache(f, 10, cacheRepo = tmpDir) })
#> [[1]] #> [1] 0.5907455 0.7917850 0.3346887 0.4321125 0.1253289 0.5792170 0.2656353 #> [8] 0.3847474 0.7882855 0.6997347 #> attr(,"tags") #> [1] "cacheId:2bbb84ec118e7aaca79ce6eabdfa6f92" #> attr(,"call") #> [1] "" #> #> [[2]] #> [1] -0.97366532 -0.71016005 0.01809067 -1.44506438 0.93872973 0.03078885 #> [7] 0.86838197 -0.58685645 -0.22234218 -0.13920560 #> attr(,"tags") #> [1] "cacheId:f955149ae1e51f7251308f1aa624e612" #> attr(,"call") #> [1] "" #>
# clear out any stub artifacts showCache(tmpDir)
#> artifact tagKey #> 1: 6256d0e43e0b8490a2b36c6e7a4b69b8 format #> 2: 6256d0e43e0b8490a2b36c6e7a4b69b8 name #> 3: 6256d0e43e0b8490a2b36c6e7a4b69b8 class #> 4: 6256d0e43e0b8490a2b36c6e7a4b69b8 date #> 5: 6256d0e43e0b8490a2b36c6e7a4b69b8 function #> 6: 6256d0e43e0b8490a2b36c6e7a4b69b8 object.size #> 7: 6256d0e43e0b8490a2b36c6e7a4b69b8 accessed #> 8: 6256d0e43e0b8490a2b36c6e7a4b69b8 cacheId #> 9: e7eeecfcaae30139e1ebd76c20fdbea0 format #> 10: e7eeecfcaae30139e1ebd76c20fdbea0 name #> 11: e7eeecfcaae30139e1ebd76c20fdbea0 class #> 12: e7eeecfcaae30139e1ebd76c20fdbea0 date #> 13: e7eeecfcaae30139e1ebd76c20fdbea0 function #> 14: e7eeecfcaae30139e1ebd76c20fdbea0 object.size #> 15: e7eeecfcaae30139e1ebd76c20fdbea0 accessed #> 16: e7eeecfcaae30139e1ebd76c20fdbea0 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:32 #> 2: Cache 2017-09-05 16:33:32 #> 3: numeric 2017-09-05 16:33:32 #> 4: 2017-09-05 16:33:32 2017-09-05 16:33:32 #> 5: f 2017-09-05 16:33:32 #> 6: 624 2017-09-05 16:33:32 #> 7: 2017-09-05 16:33:32 2017-09-05 16:33:32 #> 8: 2bbb84ec118e7aaca79ce6eabdfa6f92 2017-09-05 16:33:32 #> 9: rda 2017-09-05 16:33:32 #> 10: Cache 2017-09-05 16:33:32 #> 11: numeric 2017-09-05 16:33:32 #> 12: 2017-09-05 16:33:32 2017-09-05 16:33:32 #> 13: f 2017-09-05 16:33:32 #> 14: 624 2017-09-05 16:33:32 #> 15: 2017-09-05 16:33:32 2017-09-05 16:33:32 #> 16: f955149ae1e51f7251308f1aa624e612 2017-09-05 16:33:32
file2Remove <- dir(file.path(tmpDir, "gallery"), full.name = TRUE)[1] file.remove(file2Remove)
#> [1] TRUE
showCache(tmpDir) # repository directory still thinks files are there
#> artifact tagKey #> 1: 6256d0e43e0b8490a2b36c6e7a4b69b8 format #> 2: 6256d0e43e0b8490a2b36c6e7a4b69b8 name #> 3: 6256d0e43e0b8490a2b36c6e7a4b69b8 class #> 4: 6256d0e43e0b8490a2b36c6e7a4b69b8 date #> 5: 6256d0e43e0b8490a2b36c6e7a4b69b8 function #> 6: 6256d0e43e0b8490a2b36c6e7a4b69b8 object.size #> 7: 6256d0e43e0b8490a2b36c6e7a4b69b8 accessed #> 8: 6256d0e43e0b8490a2b36c6e7a4b69b8 cacheId #> 9: e7eeecfcaae30139e1ebd76c20fdbea0 format #> 10: e7eeecfcaae30139e1ebd76c20fdbea0 name #> 11: e7eeecfcaae30139e1ebd76c20fdbea0 class #> 12: e7eeecfcaae30139e1ebd76c20fdbea0 date #> 13: e7eeecfcaae30139e1ebd76c20fdbea0 function #> 14: e7eeecfcaae30139e1ebd76c20fdbea0 object.size #> 15: e7eeecfcaae30139e1ebd76c20fdbea0 accessed #> 16: e7eeecfcaae30139e1ebd76c20fdbea0 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:32 #> 2: Cache 2017-09-05 16:33:32 #> 3: numeric 2017-09-05 16:33:32 #> 4: 2017-09-05 16:33:32 2017-09-05 16:33:32 #> 5: f 2017-09-05 16:33:32 #> 6: 624 2017-09-05 16:33:32 #> 7: 2017-09-05 16:33:32 2017-09-05 16:33:32 #> 8: 2bbb84ec118e7aaca79ce6eabdfa6f92 2017-09-05 16:33:32 #> 9: rda 2017-09-05 16:33:32 #> 10: Cache 2017-09-05 16:33:32 #> 11: numeric 2017-09-05 16:33:32 #> 12: 2017-09-05 16:33:32 2017-09-05 16:33:32 #> 13: f 2017-09-05 16:33:32 #> 14: 624 2017-09-05 16:33:32 #> 15: 2017-09-05 16:33:32 2017-09-05 16:33:32 #> 16: f955149ae1e51f7251308f1aa624e612 2017-09-05 16:33:32
# run clearStubArtifacts suppressWarnings(clearStubArtifacts(tmpDir)) showCache(tmpDir) # stubs are removed
#> artifact tagKey #> 1: e7eeecfcaae30139e1ebd76c20fdbea0 format #> 2: e7eeecfcaae30139e1ebd76c20fdbea0 name #> 3: e7eeecfcaae30139e1ebd76c20fdbea0 class #> 4: e7eeecfcaae30139e1ebd76c20fdbea0 date #> 5: e7eeecfcaae30139e1ebd76c20fdbea0 function #> 6: e7eeecfcaae30139e1ebd76c20fdbea0 object.size #> 7: e7eeecfcaae30139e1ebd76c20fdbea0 accessed #> 8: e7eeecfcaae30139e1ebd76c20fdbea0 cacheId #> tagValue createdDate #> 1: rda 2017-09-05 16:33:32 #> 2: Cache 2017-09-05 16:33:32 #> 3: numeric 2017-09-05 16:33:32 #> 4: 2017-09-05 16:33:32 2017-09-05 16:33:32 #> 5: f 2017-09-05 16:33:32 #> 6: 624 2017-09-05 16:33:32 #> 7: 2017-09-05 16:33:32 2017-09-05 16:33:32 #> 8: f955149ae1e51f7251308f1aa624e612 2017-09-05 16:33:32
# cleanup clearCache(tmpDir) unlink(tmpDir, recursive = TRUE)