00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00090 #include "jsoc_main.h"
00091 #include "drms.h"
00092 #include "drms_names.h"
00093 #include <unistd.h>
00094 #include <strings.h>
00095
00096
00097
00098
00099
00100
00101
00102 ModuleArgs_t module_args[] = {
00103 {ARG_STRING, "series", "", "Series name to retrieve from"},
00104 {ARG_STRING, "to", "", "Target dir to cp to"},
00105 {ARG_STRING, "dirkey", "dirname", "Keyword containing the dir name"},
00106 {ARG_FLAG, "l", "0", "Link instead to the retrieved dir in the SUMS storage"},
00107 {ARG_END, NULL, NULL}
00108 };
00109
00110 char *module_name = "retrieve_dir";
00111
00112
00113 int verbose = 0;
00114
00115
00116 int DoIt(void)
00117 {
00118 int status = 0;
00119
00120 char *series;
00121 DRMS_RecordSet_t *recordset;
00122 int irec;
00123 int wantlink = cmdparams_get_int(&cmdparams, "l", NULL);
00124
00125 char *destination;
00126 char *dirkey;
00127
00128 series = cmdparams_get_str(&cmdparams, "series", NULL);
00129 destination = cmdparams_get_str(&cmdparams, "to", NULL);
00130 dirkey = cmdparams_get_str(&cmdparams, "dirkey", NULL);
00131
00132
00133 recordset = drms_open_records(drms_env, series, &status);
00134 if (status)
00135 {
00136 fprintf(stderr,"retrieve_dir target NOT_FOUND, drms_open_records failed, series=%s, status=%d.\n"
00137 "Aborting.\n", series,status);
00138 return(1);
00139 }
00140 if (recordset->n > 1)
00141 printf("%d records matched.\n", recordset->n);
00142
00143 for (irec = 0; irec< recordset->n; irec++)
00144 {
00145 DRMS_Record_t *rec = recordset->records[irec];
00146 char path[DRMS_MAXPATHLEN];
00147 char *dirname, *cptr;
00148
00149 dirname = drms_getkey_string(rec, dirkey, &status);
00150 drms_record_directory(rec, path, 1);
00151 if (*path && !status)
00152 {
00153 char cmd[DRMS_MAXPATHLEN+1024];
00154 cptr = rindex(dirname, '/');
00155 if(wantlink)
00156 sprintf(cmd, "ln -s %s%s %s", path, cptr, destination);
00157 else
00158 sprintf(cmd, "cp -r %s%s %s", path, cptr, destination);
00159 printf("cmd = %s\n", cmd);
00160 if (system(cmd))
00161 {
00162 fprintf(stderr, "retrieve_dir failed on command: %s\n",cmd);
00163 return(1);
00164 }
00165 char *note = drms_getkey_string(rec, "note", &status);
00166 printf("%s %s to %s",dirname, (wantlink ? "linked" : "retrieved"), destination);
00167 if (note && *note)
00168 printf(", note = %s\n", note);
00169 else
00170 printf(".\n");
00171 }
00172 else
00173 {
00174 printf("retrieve_dir target dir NOT_FOUND, no path or %s keyword not found in %s, abort.\n", dirkey,series);
00175 status = 1;
00176 }
00177 }
00178
00179 return(status);
00180 }