tarruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. data/README.txt +99 -0
  2. data/ext/extconf.rb +19 -0
  3. data/ext/libtar/COPYRIGHT +35 -0
  4. data/ext/libtar/ChangeLog +243 -0
  5. data/ext/libtar/ChangeLog-1.0.x +141 -0
  6. data/ext/libtar/INSTALL +183 -0
  7. data/ext/libtar/Makefile.in +51 -0
  8. data/ext/libtar/README +121 -0
  9. data/ext/libtar/TODO +10 -0
  10. data/ext/libtar/autoconf/ac_path_generic.m4 +136 -0
  11. data/ext/libtar/autoconf/aclocal.m4 +199 -0
  12. data/ext/libtar/autoconf/encap.m4 +133 -0
  13. data/ext/libtar/autoconf/install-sh +251 -0
  14. data/ext/libtar/autom4te.cache/output.0 +8102 -0
  15. data/ext/libtar/autom4te.cache/requests +112 -0
  16. data/ext/libtar/autom4te.cache/traces.0 +382 -0
  17. data/ext/libtar/compat/ChangeLog +31 -0
  18. data/ext/libtar/compat/README +12 -0
  19. data/ext/libtar/compat/TODO +4 -0
  20. data/ext/libtar/compat/basename.c +91 -0
  21. data/ext/libtar/compat/compat.h +260 -0
  22. data/ext/libtar/compat/dirname.c +96 -0
  23. data/ext/libtar/compat/fnmatch.c +237 -0
  24. data/ext/libtar/compat/gethostbyname_r.c +41 -0
  25. data/ext/libtar/compat/gethostname.c +36 -0
  26. data/ext/libtar/compat/getservbyname_r.c +41 -0
  27. data/ext/libtar/compat/glob.c +898 -0
  28. data/ext/libtar/compat/inet_aton.c +27 -0
  29. data/ext/libtar/compat/module.ac +591 -0
  30. data/ext/libtar/compat/snprintf.c +788 -0
  31. data/ext/libtar/compat/strdup.c +62 -0
  32. data/ext/libtar/compat/strlcat.c +72 -0
  33. data/ext/libtar/compat/strlcpy.c +68 -0
  34. data/ext/libtar/compat/strmode.c +199 -0
  35. data/ext/libtar/compat/strrstr.c +40 -0
  36. data/ext/libtar/compat/strsep.c +87 -0
  37. data/ext/libtar/config.h.in +187 -0
  38. data/ext/libtar/configure +8102 -0
  39. data/ext/libtar/configure.ac +114 -0
  40. data/ext/libtar/doc/Makefile.in +152 -0
  41. data/ext/libtar/doc/tar_append_file.3 +50 -0
  42. data/ext/libtar/doc/tar_block_read.3 +24 -0
  43. data/ext/libtar/doc/tar_extract_all.3 +43 -0
  44. data/ext/libtar/doc/tar_extract_file.3 +84 -0
  45. data/ext/libtar/doc/tar_open.3 +97 -0
  46. data/ext/libtar/doc/th_get_pathname.3 +63 -0
  47. data/ext/libtar/doc/th_print_long_ls.3 +22 -0
  48. data/ext/libtar/doc/th_read.3 +34 -0
  49. data/ext/libtar/doc/th_set_from_stat.3 +45 -0
  50. data/ext/libtar/lib/Makefile.in +92 -0
  51. data/ext/libtar/lib/append.c +272 -0
  52. data/ext/libtar/lib/block.c +384 -0
  53. data/ext/libtar/lib/decode.c +130 -0
  54. data/ext/libtar/lib/encode.c +237 -0
  55. data/ext/libtar/lib/extract.c +656 -0
  56. data/ext/libtar/lib/handle.c +150 -0
  57. data/ext/libtar/lib/internal.h +46 -0
  58. data/ext/libtar/lib/libtar.h +311 -0
  59. data/ext/libtar/lib/output.c +146 -0
  60. data/ext/libtar/lib/util.c +153 -0
  61. data/ext/libtar/lib/wrapper.c +175 -0
  62. data/ext/libtar/libtar/Makefile.in +73 -0
  63. data/ext/libtar/libtar/libtar.c +363 -0
  64. data/ext/libtar/listhash/ChangeLog +15 -0
  65. data/ext/libtar/listhash/TODO +21 -0
  66. data/ext/libtar/listhash/hash.c.in +344 -0
  67. data/ext/libtar/listhash/hash_new.3.in +74 -0
  68. data/ext/libtar/listhash/list.c.in +458 -0
  69. data/ext/libtar/listhash/list_new.3.in +86 -0
  70. data/ext/libtar/listhash/listhash.h.in +196 -0
  71. data/ext/libtar/listhash/module.ac +21 -0
  72. data/ext/libtar/win32/config.h +190 -0
  73. data/ext/libtar/win32/dirent.c +115 -0
  74. data/ext/libtar/win32/dirent.h +24 -0
  75. data/ext/libtar/win32/grp.h +4 -0
  76. data/ext/libtar/win32/listhash/libtar_hash.c +344 -0
  77. data/ext/libtar/win32/listhash/libtar_list.c +458 -0
  78. data/ext/libtar/win32/listhash/libtar_listhash.h +196 -0
  79. data/ext/libtar/win32/pwd.h +4 -0
  80. data/ext/libtar/win32/sys/param.h +8 -0
  81. data/ext/libtar/win32/tar.h +35 -0
  82. data/ext/libtar/win32/utime.h +6 -0
  83. data/ext/libtar/win32/win32/types.h +10 -0
  84. data/ext/tarruby.c +648 -0
  85. metadata +150 -0
@@ -0,0 +1,384 @@
1
+ /*
2
+ ** Copyright 1998-2003 University of Illinois Board of Trustees
3
+ ** Copyright 1998-2003 Mark D. Roth
4
+ ** All rights reserved.
5
+ **
6
+ ** block.c - libtar code to handle tar archive header blocks
7
+ **
8
+ ** Mark D. Roth <roth@uiuc.edu>
9
+ ** Campus Information Technologies and Educational Services
10
+ ** University of Illinois at Urbana-Champaign
11
+ */
12
+
13
+ #include <internal.h>
14
+
15
+ #include <errno.h>
16
+
17
+ #ifdef STDC_HEADERS
18
+ # include <string.h>
19
+ # include <stdlib.h>
20
+ #endif
21
+
22
+
23
+ #define BIT_ISSET(bitmask, bit) ((bitmask) & (bit))
24
+
25
+
26
+ /* read a header block */
27
+ int
28
+ th_read_internal(TAR *t)
29
+ {
30
+ int i;
31
+ int num_zero_blocks = 0;
32
+
33
+ #ifdef DEBUG
34
+ printf("==> th_read_internal(TAR=\"%s\")\n", t->pathname);
35
+ #endif
36
+
37
+ while ((i = tar_block_read(t, &(t->th_buf))) == T_BLOCKSIZE)
38
+ {
39
+ /* two all-zero blocks mark EOF */
40
+ if (t->th_buf.name[0] == '\0')
41
+ {
42
+ num_zero_blocks++;
43
+ if (!BIT_ISSET(t->options, TAR_IGNORE_EOT)
44
+ && num_zero_blocks >= 2)
45
+ return 0; /* EOF */
46
+ else
47
+ continue;
48
+ }
49
+
50
+ /* verify magic and version */
51
+ if (BIT_ISSET(t->options, TAR_CHECK_MAGIC)
52
+ && strncmp(t->th_buf.magic, TMAGIC, TMAGLEN - 1) != 0)
53
+ {
54
+ #ifdef DEBUG
55
+ puts("!!! unknown magic value in tar header");
56
+ #endif
57
+ return -2;
58
+ }
59
+
60
+ if (BIT_ISSET(t->options, TAR_CHECK_VERSION)
61
+ && strncmp(t->th_buf.version, TVERSION, TVERSLEN) != 0)
62
+ {
63
+ #ifdef DEBUG
64
+ puts("!!! unknown version value in tar header");
65
+ #endif
66
+ return -2;
67
+ }
68
+
69
+ /* check chksum */
70
+ if (!BIT_ISSET(t->options, TAR_IGNORE_CRC)
71
+ && !th_crc_ok(t))
72
+ {
73
+ #ifdef DEBUG
74
+ puts("!!! tar header checksum error");
75
+ #endif
76
+ return -2;
77
+ }
78
+
79
+ break;
80
+ }
81
+
82
+ #ifdef DEBUG
83
+ printf("<== th_read_internal(): returning %d\n", i);
84
+ #endif
85
+ return i;
86
+ }
87
+
88
+
89
+ /* wrapper function for th_read_internal() to handle GNU extensions */
90
+ int
91
+ th_read(TAR *t)
92
+ {
93
+ int i, j;
94
+ size_t sz;
95
+ char *ptr;
96
+
97
+ #ifdef DEBUG
98
+ printf("==> th_read(t=0x%lx)\n", t);
99
+ #endif
100
+
101
+ if (t->th_buf.gnu_longname != NULL)
102
+ free(t->th_buf.gnu_longname);
103
+ if (t->th_buf.gnu_longlink != NULL)
104
+ free(t->th_buf.gnu_longlink);
105
+ memset(&(t->th_buf), 0, sizeof(struct tar_header));
106
+
107
+ i = th_read_internal(t);
108
+ if (i == 0)
109
+ return 1;
110
+ else if (i != T_BLOCKSIZE)
111
+ {
112
+ if (i != -1)
113
+ errno = EINVAL;
114
+ return -1;
115
+ }
116
+
117
+ /* check for GNU long link extention */
118
+ if (TH_ISLONGLINK(t))
119
+ {
120
+ sz = th_get_size(t);
121
+ j = (sz / T_BLOCKSIZE) + (sz % T_BLOCKSIZE ? 1 : 0);
122
+ #ifdef DEBUG
123
+ printf(" th_read(): GNU long linkname detected "
124
+ "(%ld bytes, %d blocks)\n", sz, j);
125
+ #endif
126
+ t->th_buf.gnu_longlink = (char *)malloc(j * T_BLOCKSIZE);
127
+ if (t->th_buf.gnu_longlink == NULL)
128
+ return -1;
129
+
130
+ for (ptr = t->th_buf.gnu_longlink; j > 0;
131
+ j--, ptr += T_BLOCKSIZE)
132
+ {
133
+ #ifdef DEBUG
134
+ printf(" th_read(): reading long linkname "
135
+ "(%d blocks left, ptr == %ld)\n", j, ptr);
136
+ #endif
137
+ i = tar_block_read(t, ptr);
138
+ if (i != T_BLOCKSIZE)
139
+ {
140
+ if (i != -1)
141
+ errno = EINVAL;
142
+ return -1;
143
+ }
144
+ #ifdef DEBUG
145
+ printf(" th_read(): read block == \"%s\"\n", ptr);
146
+ #endif
147
+ }
148
+ #ifdef DEBUG
149
+ printf(" th_read(): t->th_buf.gnu_longlink == \"%s\"\n",
150
+ t->th_buf.gnu_longlink);
151
+ #endif
152
+
153
+ i = th_read_internal(t);
154
+ if (i != T_BLOCKSIZE)
155
+ {
156
+ if (i != -1)
157
+ errno = EINVAL;
158
+ return -1;
159
+ }
160
+ }
161
+
162
+ /* check for GNU long name extention */
163
+ if (TH_ISLONGNAME(t))
164
+ {
165
+ sz = th_get_size(t);
166
+ j = (sz / T_BLOCKSIZE) + (sz % T_BLOCKSIZE ? 1 : 0);
167
+ #ifdef DEBUG
168
+ printf(" th_read(): GNU long filename detected "
169
+ "(%ld bytes, %d blocks)\n", sz, j);
170
+ #endif
171
+ t->th_buf.gnu_longname = (char *)malloc(j * T_BLOCKSIZE);
172
+ if (t->th_buf.gnu_longname == NULL)
173
+ return -1;
174
+
175
+ for (ptr = t->th_buf.gnu_longname; j > 0;
176
+ j--, ptr += T_BLOCKSIZE)
177
+ {
178
+ #ifdef DEBUG
179
+ printf(" th_read(): reading long filename "
180
+ "(%d blocks left, ptr == %ld)\n", j, ptr);
181
+ #endif
182
+ i = tar_block_read(t, ptr);
183
+ if (i != T_BLOCKSIZE)
184
+ {
185
+ if (i != -1)
186
+ errno = EINVAL;
187
+ return -1;
188
+ }
189
+ #ifdef DEBUG
190
+ printf(" th_read(): read block == \"%s\"\n", ptr);
191
+ #endif
192
+ }
193
+ #ifdef DEBUG
194
+ printf(" th_read(): t->th_buf.gnu_longname == \"%s\"\n",
195
+ t->th_buf.gnu_longname);
196
+ #endif
197
+
198
+ i = th_read_internal(t);
199
+ if (i != T_BLOCKSIZE)
200
+ {
201
+ if (i != -1)
202
+ errno = EINVAL;
203
+ return -1;
204
+ }
205
+ }
206
+
207
+ #if 0
208
+ /*
209
+ ** work-around for old archive files with broken typeflag fields
210
+ ** NOTE: I fixed this in the TH_IS*() macros instead
211
+ */
212
+
213
+ /*
214
+ ** (directories are signified with a trailing '/')
215
+ */
216
+ if (t->th_buf.typeflag == AREGTYPE
217
+ && t->th_buf.name[strlen(t->th_buf.name) - 1] == '/')
218
+ t->th_buf.typeflag = DIRTYPE;
219
+
220
+ /*
221
+ ** fallback to using mode bits
222
+ */
223
+ if (t->th_buf.typeflag == AREGTYPE)
224
+ {
225
+ mode = (mode_t)oct_to_int(t->th_buf.mode);
226
+
227
+ if (S_ISREG(mode))
228
+ t->th_buf.typeflag = REGTYPE;
229
+ else if (S_ISDIR(mode))
230
+ t->th_buf.typeflag = DIRTYPE;
231
+ else if (S_ISFIFO(mode))
232
+ t->th_buf.typeflag = FIFOTYPE;
233
+ else if (S_ISCHR(mode))
234
+ t->th_buf.typeflag = CHRTYPE;
235
+ else if (S_ISBLK(mode))
236
+ t->th_buf.typeflag = BLKTYPE;
237
+ else if (S_ISLNK(mode))
238
+ t->th_buf.typeflag = SYMTYPE;
239
+ }
240
+ #endif
241
+
242
+ return 0;
243
+ }
244
+
245
+
246
+ /* write a header block */
247
+ int
248
+ th_write(TAR *t)
249
+ {
250
+ int i, j;
251
+ char type2;
252
+ size_t sz, sz2;
253
+ char *ptr;
254
+ char buf[T_BLOCKSIZE];
255
+
256
+ #ifdef DEBUG
257
+ printf("==> th_write(TAR=\"%s\")\n", t->pathname);
258
+ th_print(t);
259
+ #endif
260
+
261
+ if ((t->options & TAR_GNU) && t->th_buf.gnu_longlink != NULL)
262
+ {
263
+ #ifdef DEBUG
264
+ printf("th_write(): using gnu_longlink (\"%s\")\n",
265
+ t->th_buf.gnu_longlink);
266
+ #endif
267
+ /* save old size and type */
268
+ type2 = t->th_buf.typeflag;
269
+ sz2 = th_get_size(t);
270
+
271
+ /* write out initial header block with fake size and type */
272
+ t->th_buf.typeflag = GNU_LONGLINK_TYPE;
273
+ sz = strlen(t->th_buf.gnu_longlink);
274
+ th_set_size(t, sz);
275
+ th_finish(t);
276
+ i = tar_block_write(t, &(t->th_buf));
277
+ if (i != T_BLOCKSIZE)
278
+ {
279
+ if (i != -1)
280
+ errno = EINVAL;
281
+ return -1;
282
+ }
283
+
284
+ /* write out extra blocks containing long name */
285
+ for (j = (sz / T_BLOCKSIZE) + (sz % T_BLOCKSIZE ? 1 : 0),
286
+ ptr = t->th_buf.gnu_longlink; j > 1;
287
+ j--, ptr += T_BLOCKSIZE)
288
+ {
289
+ i = tar_block_write(t, ptr);
290
+ if (i != T_BLOCKSIZE)
291
+ {
292
+ if (i != -1)
293
+ errno = EINVAL;
294
+ return -1;
295
+ }
296
+ }
297
+ memset(buf, 0, T_BLOCKSIZE);
298
+ strncpy(buf, ptr, T_BLOCKSIZE);
299
+ i = tar_block_write(t, &buf);
300
+ if (i != T_BLOCKSIZE)
301
+ {
302
+ if (i != -1)
303
+ errno = EINVAL;
304
+ return -1;
305
+ }
306
+
307
+ /* reset type and size to original values */
308
+ t->th_buf.typeflag = type2;
309
+ th_set_size(t, sz2);
310
+ }
311
+
312
+ if ((t->options & TAR_GNU) && t->th_buf.gnu_longname != NULL)
313
+ {
314
+ #ifdef DEBUG
315
+ printf("th_write(): using gnu_longname (\"%s\")\n",
316
+ t->th_buf.gnu_longname);
317
+ #endif
318
+ /* save old size and type */
319
+ type2 = t->th_buf.typeflag;
320
+ sz2 = th_get_size(t);
321
+
322
+ /* write out initial header block with fake size and type */
323
+ t->th_buf.typeflag = GNU_LONGNAME_TYPE;
324
+ sz = strlen(t->th_buf.gnu_longname);
325
+ th_set_size(t, sz);
326
+ th_finish(t);
327
+ i = tar_block_write(t, &(t->th_buf));
328
+ if (i != T_BLOCKSIZE)
329
+ {
330
+ if (i != -1)
331
+ errno = EINVAL;
332
+ return -1;
333
+ }
334
+
335
+ /* write out extra blocks containing long name */
336
+ for (j = (sz / T_BLOCKSIZE) + (sz % T_BLOCKSIZE ? 1 : 0),
337
+ ptr = t->th_buf.gnu_longname; j > 1;
338
+ j--, ptr += T_BLOCKSIZE)
339
+ {
340
+ i = tar_block_write(t, ptr);
341
+ if (i != T_BLOCKSIZE)
342
+ {
343
+ if (i != -1)
344
+ errno = EINVAL;
345
+ return -1;
346
+ }
347
+ }
348
+ memset(buf, 0, T_BLOCKSIZE);
349
+ strncpy(buf, ptr, T_BLOCKSIZE);
350
+ i = tar_block_write(t, &buf);
351
+ if (i != T_BLOCKSIZE)
352
+ {
353
+ if (i != -1)
354
+ errno = EINVAL;
355
+ return -1;
356
+ }
357
+
358
+ /* reset type and size to original values */
359
+ t->th_buf.typeflag = type2;
360
+ th_set_size(t, sz2);
361
+ }
362
+
363
+ th_finish(t);
364
+
365
+ #ifdef DEBUG
366
+ /* print tar header */
367
+ th_print(t);
368
+ #endif
369
+
370
+ i = tar_block_write(t, &(t->th_buf));
371
+ if (i != T_BLOCKSIZE)
372
+ {
373
+ if (i != -1)
374
+ errno = EINVAL;
375
+ return -1;
376
+ }
377
+
378
+ #ifdef DEBUG
379
+ puts("th_write(): returning 0");
380
+ #endif
381
+ return 0;
382
+ }
383
+
384
+
@@ -0,0 +1,130 @@
1
+ /*
2
+ ** Copyright 1998-2003 University of Illinois Board of Trustees
3
+ ** Copyright 1998-2003 Mark D. Roth
4
+ ** All rights reserved.
5
+ **
6
+ ** decode.c - libtar code to decode tar header blocks
7
+ **
8
+ ** Mark D. Roth <roth@uiuc.edu>
9
+ ** Campus Information Technologies and Educational Services
10
+ ** University of Illinois at Urbana-Champaign
11
+ */
12
+
13
+ #include <internal.h>
14
+
15
+ #include <stdio.h>
16
+ #include <sys/param.h>
17
+ #include <pwd.h>
18
+ #include <grp.h>
19
+
20
+ #ifdef STDC_HEADERS
21
+ # include <string.h>
22
+ #endif
23
+
24
+
25
+ /* determine full path name */
26
+ char *
27
+ th_get_pathname(TAR *t)
28
+ {
29
+ char filename[MAXPATHLEN];
30
+
31
+ if (t->th_buf.gnu_longname)
32
+ return strdup(t->th_buf.gnu_longname);
33
+
34
+ if (t->th_buf.prefix[0] != '\0')
35
+ {
36
+ snprintf(filename, sizeof(filename), "%.155s/%.100s",
37
+ t->th_buf.prefix, t->th_buf.name);
38
+ return strdup(filename);
39
+ }
40
+
41
+ snprintf(filename, sizeof(filename), "%.100s", t->th_buf.name);
42
+ return strdup(filename);
43
+ }
44
+
45
+
46
+ uid_t
47
+ th_get_uid(TAR *t)
48
+ {
49
+ int uid;
50
+ #ifndef _WIN32 // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
51
+ struct passwd *pw;
52
+
53
+ pw = getpwnam(t->th_buf.uname);
54
+ if (pw != NULL)
55
+ return pw->pw_uid;
56
+ #endif
57
+
58
+ /* if the password entry doesn't exist */
59
+ sscanf(t->th_buf.uid, "%o", &uid);
60
+ return uid;
61
+ }
62
+
63
+
64
+ gid_t
65
+ th_get_gid(TAR *t)
66
+ {
67
+ int gid;
68
+ #ifndef _WIN32 // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
69
+ struct group *gr;
70
+
71
+ gr = getgrnam(t->th_buf.gname);
72
+ if (gr != NULL)
73
+ return gr->gr_gid;
74
+ #endif
75
+
76
+ /* if the group entry doesn't exist */
77
+ sscanf(t->th_buf.gid, "%o", &gid);
78
+ return gid;
79
+ }
80
+
81
+
82
+ mode_t
83
+ th_get_mode(TAR *t)
84
+ {
85
+ mode_t mode;
86
+
87
+ mode = (mode_t)oct_to_int(t->th_buf.mode);
88
+ if (! (mode & S_IFMT))
89
+ {
90
+ switch (t->th_buf.typeflag)
91
+ {
92
+ #ifndef _WIN32 // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
93
+ case SYMTYPE:
94
+ mode |= S_IFLNK;
95
+ break;
96
+ #endif
97
+ case CHRTYPE:
98
+ mode |= S_IFCHR;
99
+ break;
100
+ #ifndef _WIN32 // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
101
+ case BLKTYPE:
102
+ mode |= S_IFBLK;
103
+ break;
104
+ #endif
105
+ case DIRTYPE:
106
+ mode |= S_IFDIR;
107
+ break;
108
+ #ifndef _WIN32 // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
109
+ case FIFOTYPE:
110
+ mode |= S_IFIFO;
111
+ break;
112
+ #endif
113
+ case AREGTYPE:
114
+ if (t->th_buf.name[strlen(t->th_buf.name) - 1] == '/')
115
+ {
116
+ mode |= S_IFDIR;
117
+ break;
118
+ }
119
+ /* FALLTHROUGH */
120
+ case LNKTYPE:
121
+ case REGTYPE:
122
+ default:
123
+ mode |= S_IFREG;
124
+ }
125
+ }
126
+
127
+ return mode;
128
+ }
129
+
130
+