]> Creatis software - clitk.git/commitdiff
wrote upload function
authorpgueth <pgueth@kingkong.grid.creatis.insa-lyon.fr>
Fri, 4 Mar 2011 14:06:50 +0000 (15:06 +0100)
committerDavid Sarrut <david.sarrut@creatis.insa-lyon.fr>
Thu, 20 Jun 2013 11:14:23 +0000 (13:14 +0200)
grid/common.sh

index c466050077c53d5b93f20bc216fdbd292d367084..ab6b527a8666f08b7a0137119f0f67f0da5db340 100644 (file)
@@ -27,11 +27,28 @@ test "${answer}" == "n" && return 1
 check_user "${prompt}"
 }
 
+# checks if the lfn file exists
 function file_exists {
 lfnfile="${1:?"provide lfn to file"}"
 lfc-ls ${lfnfile} 2>&1 > /dev/null
 }
 
+# upload file to grid storage element
+# source can be a relative or an absolute path to the source file 
+# dest must be the lfn to the target **file** (not the directory) 
+# if dest already exists, it prompts the user for overwritting
+function upload_file {
+sourcefile=${1:?"provide source file"}
+destlfn=${2:?"provide destination file lfn"}
+sourcefile="$(readlink -f "${sourcefile}")" # convert to absolute path
+test -f "${sourcefile}" || error "can't find ${sourcefile}"
+file_exists ${destlfn} && ( \
+       check_user "${destlfn} already exists. overwrite it?" || return 2 && \
+       lcg-del -a "lfn:${destlfn}" || error "failed to delete ${destlfn}" \
+) && \
+lcg-cr -v -d ccsrm02.in2p3.fr -l "lfn:${destlfn}" "file:${sourcefile}" 
+}
+
 
 # common path used
 lfnbase="/grid/biomed/creatis/fgate/"