Skip to contents

This is a secure method of changing the "path" field of an entry in msrawfiles. The filename is not changed and must remain the same. It will check that both files are the same before making the change.

Usage

changeMsrawfilePath(rfIndex, oldPath, newPath, checkType = "md5")

Arguments

rfIndex

index name for msrawfiles table

oldPath

Current path in msrawfiles table

newPath

New path

checkType

Method to check that files are the same, either "md5" (default) or "filesize"

Value

TRUE if change was successful (invisibly)

Details

Both files must exist when making the change. The function takes some time if it compares md5-checksums of the two files. For large numbers of files use the filesize check.

Examples

if (FALSE) { # \dontrun{
library(ntsportal)
connectNtsportal()

ind <- "ntsp_msrawfiles"
res <- esSearchPaged(ind, sort = "path", searchBody = list(query = list(regexp = list(path = "/srv.*"))), source = "path")$hits$hits
partToRemove <- "/srv/cifs-mounts/g2/G/G2/HRMS/Messdaten/"
paths <- sapply(res, function(x) x[["_source"]]$path)
oldPaths <- data.frame(oldPath = paths, relPath = sub(partToRemove, "", paths))
relPaths <- list.files("/beegfs/nts/ntsportal/msrawfiles", recursive = T)
newPaths <- data.frame(
  newPath = paste0("/beegfs/nts/ntsportal/msrawfiles/", relPaths),
  relPath = relPaths
)

oldAndNewPaths <- merge(oldPaths, newPaths, all.x = T, by = "relPath")

for (i in 1:nrow(oldAndNewPaths)) {
  changeMsrawfilePath(ind, oldAndNewPaths$oldPath[i], oldAndNewPaths$newPath[i], checkType = "filesize")  
}
} # }