1 // This file is part of BOINC.
2 // http://boinc.berkeley.edu
3 // Copyright (C) 2008 University of California
4 //
5 // BOINC is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License
7 // as published by the Free Software Foundation,
8 // either version 3 of the License, or (at your option) any later version.
9 //
10 // BOINC is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 // See the GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
17
18 // dir_hier_move src_dir dst_dir fanout
19 //
20 // move files from src_dir (flat) into dst_dir (hierarchical)
21 // with the given fanout
22
23 #include "config.h"
24 #include <cstdio>
25 #include <string>
26 #include <cstdlib>
27 #include <cerrno>
28
29 #include "error_numbers.h"
30 #include "filesys.h"
31 #include "sched_util.h"
32 #include "util.h"
33
34 const char *usage =
35 "\nUsage: dir_hier_move <src_dir> <dst_dir> <fanout>\n"
36 "Moves files from <src_dir> (flat) into <dst_dir> (hierarchical) with the given <fanout>\n\n";
37
main(int argc,char ** argv)38 int main(int argc, char** argv) {
39 char* src_dir, *dst_dir;
40 int fanout=0;
41 std::string filename;
42 char dst_path[MAXPATHLEN], src_path[MAXPATHLEN];
43 int retval;
44
45 if ( (argc == 1) || !strcmp(argv[1], "-h") || !strcmp(argv[1],"--help") || (argc != 4) ) {
46 fprintf(stderr, "%s", usage);
47 exit(1);
48 }
49 src_dir = argv[1];
50 dst_dir = argv[2];
51 fanout = atoi(argv[3]);
52 if (!fanout) {
53 fprintf(stderr, "%s", usage);
54 exit(1);
55 }
56
57 DirScanner scanner(src_dir);
58 while (scanner.scan(filename)) {
59 retval = dir_hier_path(filename.c_str(), dst_dir, fanout, dst_path, true);
60 if (retval) {
61 fprintf(stderr, "dir_hier_path: %s\n", boincerror(retval));
62 exit(1);
63 }
64 snprintf(src_path, sizeof(src_path), "%s/%s", src_dir, filename.c_str());
65 retval = rename(src_path, dst_path);
66 if (retval) {
67 perror("rename");
68 exit(1);
69 }
70 }
71 }
72
73 const char *BOINC_RCSID_d6492ba662 = "$Id$";
74