updated on Sat Jan 14 12:12:45 UTC 2012
[aur-mirror.git] / convertfs / convertfs-ftwmv.patch
blob097b53a902fcae225a329ea69189cddc5c771f4c
1 --- convertfs.old/Makefile 2002-01-10 19:17:48.000000000 +0200
2 +++ convertfs/Makefile 2009-09-03 20:02:37.304624133 +0300
3 @@ -1,6 +1,6 @@
4 CFLAGS=-g -Wall -O3
6 -all: devclone devremap prepindex
7 +all: devclone devremap prepindex ftwmv
8 sync
10 devclone: devclone.c
11 @@ -12,5 +12,8 @@
12 prepindex: prepindex.c convertfs.h
13 gcc -o prepindex prepindex.c $(CFLAGS)
15 +ftwmv: ftwmv.c
16 + gcc -o ftwmv ftwmv.c $(CFLAGS)
18 clean:
19 - rm -f *.o devclone devremap prepindex core
20 + rm -f *.o devclone devremap prepindex ftwmv core
21 --- convertfs.old/contrib/convertfs 2009-09-03 20:05:24.054609708 +0300
22 +++ convertfs/contrib/convertfs 2009-09-03 20:01:17.717963475 +0300
23 @@ -208,7 +208,8 @@
24 [ "x$file" != "x$fsindex_name" ] &&
25 [ "x$file" != "xlost+found" ] &&
26 [ "x$file" != "x$fssuper_name" ]; then
27 - mv -f "$fs1root/$file" "$fs2root/" || error
28 + #mv -f "$fs1root/$file" "$fs2root/" || error
29 + ftwmv "$fs1root/$file" "$fs2root/$file" || error
31 done
32 ls -lA "$fs2root"
33 --- convertfs.old/ftwmv.c 1970-01-01 02:00:00.000000000 +0200
34 +++ convertfs/ftwmv.c 2009-09-03 19:25:45.311509000 +0300
35 @@ -0,0 +1,132 @@
36 +/*
37 + ftw - file tree walk
38 + Copyright (C) 2004 Guus Sliepen <guus@sliepen.eu.org>
40 + This program is free software; you can redistribute it and/or modify
41 + it under the terms of the GNU General Public License as published by
42 + the Free Software Foundation; either version 2 of the License, or
43 + (at your option) any later version.
45 + This program is distributed in the hope that it will be useful,
46 + but WITHOUT ANY WARRANTY; without even the implied warranty of
47 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 + GNU General Public License for more details.
50 + You should have received a copy of the GNU General Public License
51 + along with this program; if not, write to the Free Software
52 + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
53 +*/
55 +#define _GNU_SOURCE 1
57 +#include <stdio.h>
58 +#include <stdlib.h>
59 +#include <stdbool.h>
60 +#include <sys/types.h>
61 +#include <sys/wait.h>
62 +#include <unistd.h>
63 +#include <getopt.h>
64 +#include <string.h>
65 +#include <errno.h>
66 +#include <ftw.h>
68 +#define MAX 8192
70 +bool verbose = false;
72 +char *from, *to;
73 +int fromlen, tolen;
75 +void fromto(char *dest, const char *file) {
76 + strcpy(dest, to);
77 + strcpy(dest + tolen, file + fromlen);
80 +int mvhandler(const char *file, const struct stat *sb, int flag, struct FTW *s) {
81 + static char dest[MAX];
82 + int status;
84 + if(verbose)
85 + printf("%s\n", file);
87 + fromto(dest, file);
89 + if(flag == FTW_D) {
90 + if(mkdir(dest, sb->st_mode) == -1)
91 + fprintf(stderr, "Could not make directory %s: %s\n", dest, strerror(errno));
92 + else if(chown(dest, sb->st_uid, sb->st_gid) == -1)
93 + fprintf(stderr, "Could not set owner of %s: %s\n", dest, strerror(errno));
94 + } else {
95 + if(!fork()) {
96 + execlp("/bin/mv", "mv", file, dest, NULL);
97 + fprintf(stderr, "Could not exec /bin/mv: %s\n", strerror(errno));
98 + exit(1);
99 + }
100 + wait(&status);
103 + return 0;
106 +int rmdirhandler(const char *file, const struct stat *sb, int flag, struct FTW *s) {
107 + if(flag != FTW_D && flag != FTW_DP)
108 + return 0;
110 + if(verbose)
111 + printf("%s\n", file);
113 + if(rmdir(file) == 1)
114 + fprintf(stderr, "Could not remove directory %s: %s\n", file, strerror(errno));
116 + return 0;
119 +static struct option const long_options[] = {
120 + {"verbose", no_argument, NULL, 'v'},
121 + {"help", no_argument, NULL, 1},
122 + {NULL, 0, NULL, 0}
125 +void usage(char *argv0, bool help) {
126 + fprintf(stderr, "Usage: %s [-v] FROM TO\n", argv0);
128 + if(help) {
129 + fprintf(stderr,
130 + "\n"
131 + " -v, --verbose list all processed files\n"
132 + " --help show this help\n"
133 + "\n"
134 + );
135 + } else {
136 + fprintf(stderr, "Try '%s --help' for more information.\n", argv0);
140 +int main(int argc, char **argv) {
141 + int result, index = 0;
143 + while((result = getopt_long(argc, argv, "v", long_options, &index)) != -1) {
144 + switch(result) {
145 + case 'v':
146 + verbose = true;
147 + break;
148 + case 1:
149 + usage(argv[0], true);
150 + return 0;
151 + default:
152 + usage(argv[0], false);
153 + return 1;
157 + if(argc - optind != 2)
158 + usage(argv[0], false);
160 + from = argv[optind++];
161 + to = argv[optind++];
163 + fromlen = strlen(from);
164 + tolen = strlen(to);
166 + return nftw(from, mvhandler, 100, FTW_PHYS) ?: nftw(from, rmdirhandler, 100, FTW_PHYS | FTW_DEPTH);