changeset 7:e5a905df7e0b draft

Uploaded
author david-hoover
date Thu, 04 Oct 2012 14:48:02 -0400
parents cbe8bdc3bdac
children 01687750c862
files README cpx.c cpy.c export_local_file.xml import_local_file.xml
diffstat 5 files changed, 86 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/README	Thu Mar 08 09:18:40 2012 -0500
+++ b/README	Thu Oct 04 14:48:02 2012 -0400
@@ -15,3 +15,6 @@
 and added to your galaxy user PATH.
 
  export PATH=/usr/local/galaxy/bin:$PATH
+
+Note that filepaths are restricted to /data/... and
+/home/...  This can be changed by editing the code.
--- a/cpx.c	Thu Mar 08 09:18:40 2012 -0500
+++ b/cpx.c	Thu Oct 04 14:48:02 2012 -0400
@@ -143,10 +143,13 @@
 {
 //    printf("Copying %s to %s\n",src,dst);
 
-    int c;
+    char *c;
     FILE *fs,*ft;
     struct stat fileStat;
-
+    size_t st=10000000;
+    int numr,numw;
+   
+//    buffer = 10000;
 /* must be able to stat file */
     if (stat(src, &fileStat) < 0)
     {
@@ -172,14 +175,28 @@
         exit(1);
     }
 
-    c = getc(fs);
-    while (c != EOF) {
-        putc(c,ft);
-        c = getc(fs);
-   }
-
+    c=malloc(st);
+    while(feof(fs)==0)
+    {	
+        if((numr=fread(c,1,st,fs))!=st)
+        {
+            if(ferror(fs)!=0)
+            {
+                fprintf(stderr,"read file error.\n");
+                exit(1);
+            }
+            else if(feof(fs)!=0);
+        }
+        if((numw=fwrite(c,1,numr,ft))!=numr)
+        {
+            fprintf(stderr,"write file error.\n");
+            exit(1);
+        }
+    }	
+	
    fclose(fs);
    fclose(ft);
+   free(c);
 
    return 0;
 
@@ -240,12 +257,21 @@
         exit(1);
     }
 
+    if (!strncmp(argv[1],"/data",5) || !strncmp(argv[1],"/home",5))
+    {
+
 /* is file readable by given user? */
-    explodePath(argv[1],argv[3]);
+      explodePath(argv[1],argv[3]);
 
 /* copy the file and change the owner */
-    copyFile(argv[1],argv[2]);
-    chownToUser(argv[2]);
+      copyFile(argv[1],argv[2]);
+      chownToUser(argv[2]);
+    }
+    else 
+    {
+      fprintf(stderr,"%s: Permission denied.\n",argv[1]);
+      exit(1);
+    }
 
     exit(0);
 }
--- a/cpy.c	Thu Mar 08 09:18:40 2012 -0500
+++ b/cpy.c	Thu Oct 04 14:48:02 2012 -0400
@@ -264,9 +264,11 @@
 {
 //    printf("Copying %s to %s\n",src,dst);
 
-    int c;
+    char *c;
     FILE *fs,*ft;
     struct stat fileStat;
+    size_t st=10000000;
+    int numr,numw;
 
 /* must be able to stat file */
     if (stat(src, &fileStat) < 0)
@@ -292,15 +294,29 @@
         fprintf(stderr,"Can't write to file %s!\n",dst);
         exit(1);
     }
-
-    c = getc(fs);
-    while (c != EOF) {
-        putc(c,ft);
-        c = getc(fs);
-   }
+   
+    c=malloc(st);
+    while(feof(fs)==0)
+    {	
+        if((numr=fread(c,1,st,fs))!=st)
+        {
+            if(ferror(fs)!=0)
+            {
+                fprintf(stderr,"read file error.\n");
+                exit(1);
+            }
+            else if(feof(fs)!=0);
+        }
+        if((numw=fwrite(c,1,numr,ft))!=numr)
+        {
+            fprintf(stderr,"write file error.\n");
+            exit(1);
+        }
+    }	
 
    fclose(fs);
    fclose(ft);
+   free(c);
 
    return 0;
 
@@ -362,25 +378,34 @@
         exit(1);
     }
 
+    if (!strncmp(argv[2],"/data",5) || !strncmp(argv[2],"/home",5))
+    {
+
 /* is filepath writeable by given user? */
-    strcpy(newfile,argv[2]);
-    dir = dirname(newfile);
-    if (!notWriteable(dir,argv[3]))
-    { 
+      strcpy(newfile,argv[2]);
+      dir = dirname(newfile);
+      if (!notWriteable(dir,argv[3]))
+      { 
  
 /* is filepath readable by given user? */
-      explodePath(dir,argv[3]);
+        explodePath(dir,argv[3]);
 
 /* dest file must not exist yet */
-    if (!(stat(argv[2], &fileStat) < 0))
-    {
-        fprintf(stderr,"%s: File already exists.\n",argv[2]);
-        exit(1);
-    }
+      if (!(stat(argv[2], &fileStat) < 0))
+      {
+          fprintf(stderr,"%s: File already exists.\n",argv[2]);
+          exit(1);
+      }
 
 /* copy the file and change the owner */
-      copyFile(argv[1],argv[2]);
-      chownToGivenUser(argv[2],argv[3]);
+        copyFile(argv[1],argv[2]);
+        chownToGivenUser(argv[2],argv[3]);
+      }
+      else 
+      {
+        fprintf(stderr,"%s: Permission denied.\n",argv[2]);
+        exit(1);
+      }
     }
     else 
     {
--- a/export_local_file.xml	Thu Mar 08 09:18:40 2012 -0500
+++ b/export_local_file.xml	Thu Oct 04 14:48:02 2012 -0400
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<tool id="export_local_file" name="Export dataset" version="1.0.1">
+<tool id="export_local_file" name="Export dataset" version="1.1.0">
   <description>to a local filesytem</description>
   <command interpreter="sh">export_local_file.sh $input '$filepath' $userEmail $output</command>
   <inputs>   
--- a/import_local_file.xml	Thu Mar 08 09:18:40 2012 -0500
+++ b/import_local_file.xml	Thu Oct 04 14:48:02 2012 -0400
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<tool id="import_local_file" name="Import local file" version="1.0.1">
+<tool id="import_local_file" name="Import local file" version="1.1.0">
   <description>from a local filesystem</description>
   <command interpreter="sh">import_local_file.sh '$filepath' $output $userEmail</command>
   <inputs>