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.007070776 0.940870595 0.068209351 0.136929180 0.332817025 0.489688292 #> [7] 0.172954540 0.064939242 0.451666990 0.379402354 #> attr(,"tags") #> [1] "cacheId:c544d867e89c93fb20f0fccb922cc028" #> attr(,".Cache") #> attr(,".Cache")$newCache #> [1] TRUE #> #> attr(,"call") #> [1] "" #> #> [[2]] #> [1] 1.3364468 -0.8603562 0.6665378 -1.4215347 1.1700562 -1.4047145 #> [7] 1.1017081 0.6979863 -0.8643498 -1.0914704 #> attr(,"tags") #> [1] "cacheId:03dcbe8e18b571c397bbc2e72230d216" #> attr(,".Cache") #> attr(,".Cache")$newCache #> [1] TRUE #> #> attr(,"call") #> [1] "" #>
# clear out any stub artifacts showCache(tmpDir)
#> Cache size:
#> Total (including Rasters): 560 bytes
#> Selected objects (not including Rasters): 560 bytes
#> artifact tagKey #> 1: 98fa25376affc3ddc73deeea9a02cb4a format #> 2: 98fa25376affc3ddc73deeea9a02cb4a name #> 3: 98fa25376affc3ddc73deeea9a02cb4a class #> 4: 98fa25376affc3ddc73deeea9a02cb4a date #> 5: 98fa25376affc3ddc73deeea9a02cb4a cacheId #> 6: 98fa25376affc3ddc73deeea9a02cb4a function #> 7: 98fa25376affc3ddc73deeea9a02cb4a object.size #> 8: 98fa25376affc3ddc73deeea9a02cb4a accessed #> 9: 98fa25376affc3ddc73deeea9a02cb4a otherFunctions #> 10: 98fa25376affc3ddc73deeea9a02cb4a otherFunctions #> 11: 98fa25376affc3ddc73deeea9a02cb4a otherFunctions #> 12: 98fa25376affc3ddc73deeea9a02cb4a otherFunctions #> 13: 98fa25376affc3ddc73deeea9a02cb4a otherFunctions #> 14: 98fa25376affc3ddc73deeea9a02cb4a otherFunctions #> 15: 98fa25376affc3ddc73deeea9a02cb4a otherFunctions #> 16: 98fa25376affc3ddc73deeea9a02cb4a preDigest #> 17: 98fa25376affc3ddc73deeea9a02cb4a preDigest #> 18: bb11c50b3f74ad556fc18107672898c6 format #> 19: bb11c50b3f74ad556fc18107672898c6 name #> 20: bb11c50b3f74ad556fc18107672898c6 class #> 21: bb11c50b3f74ad556fc18107672898c6 date #> 22: bb11c50b3f74ad556fc18107672898c6 cacheId #> 23: bb11c50b3f74ad556fc18107672898c6 function #> 24: bb11c50b3f74ad556fc18107672898c6 object.size #> 25: bb11c50b3f74ad556fc18107672898c6 accessed #> 26: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 27: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 28: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 29: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 30: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 31: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 32: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 33: bb11c50b3f74ad556fc18107672898c6 preDigest #> 34: bb11c50b3f74ad556fc18107672898c6 preDigest #> artifact tagKey #> tagValue createdDate #> 1: rda 2018-09-11 17:26:13 #> 2: 98fa25376affc3ddc73deeea9a02cb4a 2018-09-11 17:26:13 #> 3: numeric 2018-09-11 17:26:13 #> 4: 2018-09-11 17:26:13 2018-09-11 17:26:13 #> 5: c544d867e89c93fb20f0fccb922cc028 2018-09-11 17:26:13 #> 6: f 2018-09-11 17:26:13 #> 7: 1120 2018-09-11 17:26:13 #> 8: 2018-09-11 17:26:13 2018-09-11 17:26:13 #> 9: withCallingHandlers 2018-09-11 17:26:13 #> 10: saveRDS 2018-09-11 17:26:13 #> 11: do.call 2018-09-11 17:26:13 #> 12: build_site_local 2018-09-11 17:26:13 #> 13: build_reference 2018-09-11 17:26:13 #> 14: data_reference_topic 2018-09-11 17:26:13 #> 15: try 2018-09-11 17:26:13 #> 16: n:c192d58bc0a9ddf2b5f916d929bccc08 2018-09-11 17:26:13 #> 17: .FUN:179092fbad3ec261e58bc89bc8a703c3 2018-09-11 17:26:13 #> 18: rda 2018-09-11 17:26:13 #> 19: bb11c50b3f74ad556fc18107672898c6 2018-09-11 17:26:13 #> 20: numeric 2018-09-11 17:26:13 #> 21: 2018-09-11 17:26:13 2018-09-11 17:26:13 #> 22: 03dcbe8e18b571c397bbc2e72230d216 2018-09-11 17:26:13 #> 23: f 2018-09-11 17:26:13 #> 24: 1120 2018-09-11 17:26:13 #> 25: 2018-09-11 17:26:13 2018-09-11 17:26:13 #> 26: withCallingHandlers 2018-09-11 17:26:13 #> 27: saveRDS 2018-09-11 17:26:13 #> 28: do.call 2018-09-11 17:26:13 #> 29: build_site_local 2018-09-11 17:26:14 #> 30: build_reference 2018-09-11 17:26:14 #> 31: data_reference_topic 2018-09-11 17:26:14 #> 32: try 2018-09-11 17:26:14 #> 33: n:c192d58bc0a9ddf2b5f916d929bccc08 2018-09-11 17:26:14 #> 34: .FUN:a979d0700a6ef8c7c18736096ff1d522 2018-09-11 17:26:14 #> tagValue createdDate
file2Remove <- dir(file.path(tmpDir, "gallery"), full.name = TRUE)[1] file.remove(file2Remove)
#> [1] TRUE
showCache(tmpDir) # repository directory still thinks files are there
#> Cache size:
#> Total (including Rasters): 560 bytes
#> Selected objects (not including Rasters): 560 bytes
#> artifact tagKey #> 1: 98fa25376affc3ddc73deeea9a02cb4a format #> 2: 98fa25376affc3ddc73deeea9a02cb4a name #> 3: 98fa25376affc3ddc73deeea9a02cb4a class #> 4: 98fa25376affc3ddc73deeea9a02cb4a date #> 5: 98fa25376affc3ddc73deeea9a02cb4a cacheId #> 6: 98fa25376affc3ddc73deeea9a02cb4a function #> 7: 98fa25376affc3ddc73deeea9a02cb4a object.size #> 8: 98fa25376affc3ddc73deeea9a02cb4a accessed #> 9: 98fa25376affc3ddc73deeea9a02cb4a otherFunctions #> 10: 98fa25376affc3ddc73deeea9a02cb4a otherFunctions #> 11: 98fa25376affc3ddc73deeea9a02cb4a otherFunctions #> 12: 98fa25376affc3ddc73deeea9a02cb4a otherFunctions #> 13: 98fa25376affc3ddc73deeea9a02cb4a otherFunctions #> 14: 98fa25376affc3ddc73deeea9a02cb4a otherFunctions #> 15: 98fa25376affc3ddc73deeea9a02cb4a otherFunctions #> 16: 98fa25376affc3ddc73deeea9a02cb4a preDigest #> 17: 98fa25376affc3ddc73deeea9a02cb4a preDigest #> 18: bb11c50b3f74ad556fc18107672898c6 format #> 19: bb11c50b3f74ad556fc18107672898c6 name #> 20: bb11c50b3f74ad556fc18107672898c6 class #> 21: bb11c50b3f74ad556fc18107672898c6 date #> 22: bb11c50b3f74ad556fc18107672898c6 cacheId #> 23: bb11c50b3f74ad556fc18107672898c6 function #> 24: bb11c50b3f74ad556fc18107672898c6 object.size #> 25: bb11c50b3f74ad556fc18107672898c6 accessed #> 26: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 27: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 28: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 29: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 30: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 31: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 32: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 33: bb11c50b3f74ad556fc18107672898c6 preDigest #> 34: bb11c50b3f74ad556fc18107672898c6 preDigest #> artifact tagKey #> tagValue createdDate #> 1: rda 2018-09-11 17:26:13 #> 2: 98fa25376affc3ddc73deeea9a02cb4a 2018-09-11 17:26:13 #> 3: numeric 2018-09-11 17:26:13 #> 4: 2018-09-11 17:26:13 2018-09-11 17:26:13 #> 5: c544d867e89c93fb20f0fccb922cc028 2018-09-11 17:26:13 #> 6: f 2018-09-11 17:26:13 #> 7: 1120 2018-09-11 17:26:13 #> 8: 2018-09-11 17:26:13 2018-09-11 17:26:13 #> 9: withCallingHandlers 2018-09-11 17:26:13 #> 10: saveRDS 2018-09-11 17:26:13 #> 11: do.call 2018-09-11 17:26:13 #> 12: build_site_local 2018-09-11 17:26:13 #> 13: build_reference 2018-09-11 17:26:13 #> 14: data_reference_topic 2018-09-11 17:26:13 #> 15: try 2018-09-11 17:26:13 #> 16: n:c192d58bc0a9ddf2b5f916d929bccc08 2018-09-11 17:26:13 #> 17: .FUN:179092fbad3ec261e58bc89bc8a703c3 2018-09-11 17:26:13 #> 18: rda 2018-09-11 17:26:13 #> 19: bb11c50b3f74ad556fc18107672898c6 2018-09-11 17:26:13 #> 20: numeric 2018-09-11 17:26:13 #> 21: 2018-09-11 17:26:13 2018-09-11 17:26:13 #> 22: 03dcbe8e18b571c397bbc2e72230d216 2018-09-11 17:26:13 #> 23: f 2018-09-11 17:26:13 #> 24: 1120 2018-09-11 17:26:13 #> 25: 2018-09-11 17:26:13 2018-09-11 17:26:13 #> 26: withCallingHandlers 2018-09-11 17:26:13 #> 27: saveRDS 2018-09-11 17:26:13 #> 28: do.call 2018-09-11 17:26:13 #> 29: build_site_local 2018-09-11 17:26:14 #> 30: build_reference 2018-09-11 17:26:14 #> 31: data_reference_topic 2018-09-11 17:26:14 #> 32: try 2018-09-11 17:26:14 #> 33: n:c192d58bc0a9ddf2b5f916d929bccc08 2018-09-11 17:26:14 #> 34: .FUN:a979d0700a6ef8c7c18736096ff1d522 2018-09-11 17:26:14 #> tagValue createdDate
# run clearStubArtifacts suppressWarnings(clearStubArtifacts(tmpDir)) showCache(tmpDir) # stubs are removed
#> Cache size:
#> Total (including Rasters): 280 bytes
#> Selected objects (not including Rasters): 280 bytes
#> artifact tagKey #> 1: bb11c50b3f74ad556fc18107672898c6 format #> 2: bb11c50b3f74ad556fc18107672898c6 name #> 3: bb11c50b3f74ad556fc18107672898c6 class #> 4: bb11c50b3f74ad556fc18107672898c6 date #> 5: bb11c50b3f74ad556fc18107672898c6 cacheId #> 6: bb11c50b3f74ad556fc18107672898c6 function #> 7: bb11c50b3f74ad556fc18107672898c6 object.size #> 8: bb11c50b3f74ad556fc18107672898c6 accessed #> 9: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 10: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 11: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 12: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 13: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 14: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 15: bb11c50b3f74ad556fc18107672898c6 otherFunctions #> 16: bb11c50b3f74ad556fc18107672898c6 preDigest #> 17: bb11c50b3f74ad556fc18107672898c6 preDigest #> tagValue createdDate #> 1: rda 2018-09-11 17:26:13 #> 2: bb11c50b3f74ad556fc18107672898c6 2018-09-11 17:26:13 #> 3: numeric 2018-09-11 17:26:13 #> 4: 2018-09-11 17:26:13 2018-09-11 17:26:13 #> 5: 03dcbe8e18b571c397bbc2e72230d216 2018-09-11 17:26:13 #> 6: f 2018-09-11 17:26:13 #> 7: 1120 2018-09-11 17:26:13 #> 8: 2018-09-11 17:26:13 2018-09-11 17:26:13 #> 9: withCallingHandlers 2018-09-11 17:26:13 #> 10: saveRDS 2018-09-11 17:26:13 #> 11: do.call 2018-09-11 17:26:13 #> 12: build_site_local 2018-09-11 17:26:14 #> 13: build_reference 2018-09-11 17:26:14 #> 14: data_reference_topic 2018-09-11 17:26:14 #> 15: try 2018-09-11 17:26:14 #> 16: n:c192d58bc0a9ddf2b5f916d929bccc08 2018-09-11 17:26:14 #> 17: .FUN:a979d0700a6ef8c7c18736096ff1d522 2018-09-11 17:26:14
# cleanup clearCache(tmpDir)
#> Cache size:
#> Total (including Rasters): 280 bytes
#> Selected objects (not including Rasters): 280 bytes
unlink(tmpDir, recursive = TRUE)