Skip to content

Commit

Permalink
candidate fix for #322
Browse files Browse the repository at this point in the history
  • Loading branch information
pbiecek committed Feb 19, 2018
1 parent ec09578 commit acc2f4f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 9 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Imports:
DBI,
lubridate,
RSQLite,
magrittr
magrittr,
flock
Suggests:
shiny,
dplyr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export(summaryLocalRepo)
export(summaryRemoteRepo)
export(zipLocalRepo)
export(zipRemoteRepo)
import(flock)
import(httr)
importClassesFrom(RSQLite,SQLiteDriver)
importFrom(DBI,dbConnect)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
archivist 2.3
----------------------------------------------------------------
* Examples are changed to comply with CRAN Policy ([#324](https://github.com/pbiecek/archivist/issues/324)).
* `saveToLocalRepo()` and `saveToRepo()` have now additional parameter `use_flocks`. If set up to `TRUE` then `flock` package is use to synchronize access to database ([#322](https://github.com/pbiecek/archivist/issues/322)).

archivist 2.2
----------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion R/rmFromRepo.R
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ rmFromLocalRepo <- function( md5hash, repoDir = aoptions('repoDir'), removeData
}

repoDir <- checkDirectory( repoDir )



# We will use md5hash list in checking whether md5hash is in the Repository
md5hashList <- executeSingleQuery( dir = repoDir,
paste0( "SELECT md5hash FROM artifact" ) )
Expand Down
21 changes: 20 additions & 1 deletion R/saveToRepo.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@
#' @param silent If TRUE produces no warnings.
#'
#' @param ascii A logical value. An \code{ascii} argument is passed to \link{save} function.
#'
#' @param use_flocks A logical value. If \code{TRUE} then \code{flock} package is used to lock access to a database. By default it's \code{FALSE}.
#'
#' @param artifactName The name of the artifact with which it should be archived. If \code{NULL} then object's MD5 hash will be used instead.
#'
#' @import flock
#'
#' @author
#' Marcin Kosinski , \email{m.p.kosinski@@gmail.com}
Expand Down Expand Up @@ -163,7 +166,8 @@ saveToLocalRepo <- function(
archiveSessionInfo = TRUE,
force = TRUE,
value = FALSE, ... , userTags = c(),
silent=aoptions("silent"), ascii = FALSE,
use_flocks = aoptions("use_flocks"),
silent = aoptions("silent"), ascii = FALSE,
artifactName = deparse(substitute(artifact))) {

stopifnot(is.logical(c(archiveData, archiveTags, archiveMiniature, force,
Expand All @@ -181,6 +185,13 @@ saveToLocalRepo <- function(
}

repoDir <- checkDirectory( repoDir )

# check if locks are set up
if (isTRUE(use_flocks)) {
if (dir.exists(repoDir)) {
.archivist_locker <- flock::lock(paste0(repoDir, "/archivist_database.flock"))
}
}

# check if that artifact might have been already archived
check <- executeSingleQuery( dir = repoDir ,
Expand Down Expand Up @@ -237,6 +248,14 @@ saveToLocalRepo <- function(
# whether to archive miniature
if ( archiveMiniature )
extractMiniature( artifact, md5hash, parentDir = repoDir ,... )

# check if locks are set up
if (isTRUE(use_flocks)) {
if (dir.exists(repoDir)) {
flock::unlock(.archivist_locker)
}
}

# whether to return md5hash or an artifact if valueing code is used
if ( !value ){
return( md5hash )
Expand Down
1 change: 1 addition & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ setDefaultArchivistEnv <- function() {
.ArchivistEnv$branch <- "master"
.ArchivistEnv$chain <- FALSE
.ArchivistEnv$force <- FALSE
.ArchivistEnv$use_flocks <- FALSE
.ArchivistEnv$subdir <- "/"
.ArchivistEnv$repoType <- "github"
.ArchivistEnv$silent <- TRUE
Expand Down
14 changes: 8 additions & 6 deletions man/saveToRepo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit acc2f4f

Please sign in to comment.