tarruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +99 -0
- data/ext/extconf.rb +19 -0
- data/ext/libtar/COPYRIGHT +35 -0
- data/ext/libtar/ChangeLog +243 -0
- data/ext/libtar/ChangeLog-1.0.x +141 -0
- data/ext/libtar/INSTALL +183 -0
- data/ext/libtar/Makefile.in +51 -0
- data/ext/libtar/README +121 -0
- data/ext/libtar/TODO +10 -0
- data/ext/libtar/autoconf/ac_path_generic.m4 +136 -0
- data/ext/libtar/autoconf/aclocal.m4 +199 -0
- data/ext/libtar/autoconf/encap.m4 +133 -0
- data/ext/libtar/autoconf/install-sh +251 -0
- data/ext/libtar/autom4te.cache/output.0 +8102 -0
- data/ext/libtar/autom4te.cache/requests +112 -0
- data/ext/libtar/autom4te.cache/traces.0 +382 -0
- data/ext/libtar/compat/ChangeLog +31 -0
- data/ext/libtar/compat/README +12 -0
- data/ext/libtar/compat/TODO +4 -0
- data/ext/libtar/compat/basename.c +91 -0
- data/ext/libtar/compat/compat.h +260 -0
- data/ext/libtar/compat/dirname.c +96 -0
- data/ext/libtar/compat/fnmatch.c +237 -0
- data/ext/libtar/compat/gethostbyname_r.c +41 -0
- data/ext/libtar/compat/gethostname.c +36 -0
- data/ext/libtar/compat/getservbyname_r.c +41 -0
- data/ext/libtar/compat/glob.c +898 -0
- data/ext/libtar/compat/inet_aton.c +27 -0
- data/ext/libtar/compat/module.ac +591 -0
- data/ext/libtar/compat/snprintf.c +788 -0
- data/ext/libtar/compat/strdup.c +62 -0
- data/ext/libtar/compat/strlcat.c +72 -0
- data/ext/libtar/compat/strlcpy.c +68 -0
- data/ext/libtar/compat/strmode.c +199 -0
- data/ext/libtar/compat/strrstr.c +40 -0
- data/ext/libtar/compat/strsep.c +87 -0
- data/ext/libtar/config.h.in +187 -0
- data/ext/libtar/configure +8102 -0
- data/ext/libtar/configure.ac +114 -0
- data/ext/libtar/doc/Makefile.in +152 -0
- data/ext/libtar/doc/tar_append_file.3 +50 -0
- data/ext/libtar/doc/tar_block_read.3 +24 -0
- data/ext/libtar/doc/tar_extract_all.3 +43 -0
- data/ext/libtar/doc/tar_extract_file.3 +84 -0
- data/ext/libtar/doc/tar_open.3 +97 -0
- data/ext/libtar/doc/th_get_pathname.3 +63 -0
- data/ext/libtar/doc/th_print_long_ls.3 +22 -0
- data/ext/libtar/doc/th_read.3 +34 -0
- data/ext/libtar/doc/th_set_from_stat.3 +45 -0
- data/ext/libtar/lib/Makefile.in +92 -0
- data/ext/libtar/lib/append.c +272 -0
- data/ext/libtar/lib/block.c +384 -0
- data/ext/libtar/lib/decode.c +130 -0
- data/ext/libtar/lib/encode.c +237 -0
- data/ext/libtar/lib/extract.c +656 -0
- data/ext/libtar/lib/handle.c +150 -0
- data/ext/libtar/lib/internal.h +46 -0
- data/ext/libtar/lib/libtar.h +311 -0
- data/ext/libtar/lib/output.c +146 -0
- data/ext/libtar/lib/util.c +153 -0
- data/ext/libtar/lib/wrapper.c +175 -0
- data/ext/libtar/libtar/Makefile.in +73 -0
- data/ext/libtar/libtar/libtar.c +363 -0
- data/ext/libtar/listhash/ChangeLog +15 -0
- data/ext/libtar/listhash/TODO +21 -0
- data/ext/libtar/listhash/hash.c.in +344 -0
- data/ext/libtar/listhash/hash_new.3.in +74 -0
- data/ext/libtar/listhash/list.c.in +458 -0
- data/ext/libtar/listhash/list_new.3.in +86 -0
- data/ext/libtar/listhash/listhash.h.in +196 -0
- data/ext/libtar/listhash/module.ac +21 -0
- data/ext/libtar/win32/config.h +190 -0
- data/ext/libtar/win32/dirent.c +115 -0
- data/ext/libtar/win32/dirent.h +24 -0
- data/ext/libtar/win32/grp.h +4 -0
- data/ext/libtar/win32/listhash/libtar_hash.c +344 -0
- data/ext/libtar/win32/listhash/libtar_list.c +458 -0
- data/ext/libtar/win32/listhash/libtar_listhash.h +196 -0
- data/ext/libtar/win32/pwd.h +4 -0
- data/ext/libtar/win32/sys/param.h +8 -0
- data/ext/libtar/win32/tar.h +35 -0
- data/ext/libtar/win32/utime.h +6 -0
- data/ext/libtar/win32/win32/types.h +10 -0
- data/ext/tarruby.c +648 -0
- metadata +150 -0
data/ext/tarruby.c
ADDED
@@ -0,0 +1,648 @@
|
|
1
|
+
#include <fcntl.h>
|
2
|
+
#include <errno.h>
|
3
|
+
#ifdef HAVE_ZLIB_H
|
4
|
+
#include <zlib.h>
|
5
|
+
#endif
|
6
|
+
#ifdef HAVE_BZLIB_H
|
7
|
+
#include <bzlib.h>
|
8
|
+
#endif
|
9
|
+
#include "libtar.h"
|
10
|
+
#include "ruby.h"
|
11
|
+
|
12
|
+
#ifndef RSTRING_PTR
|
13
|
+
#define RSTRING_PTR(s) (RSTRING(s)->ptr)
|
14
|
+
#endif
|
15
|
+
#ifndef RSTRING_LEN
|
16
|
+
#define RSTRING_LEN(s) (RSTRING(s)->len)
|
17
|
+
#endif
|
18
|
+
|
19
|
+
#ifdef TARRUBY_EXPORTS
|
20
|
+
#define DLLEXPORT __declspec(dllexport)
|
21
|
+
#else
|
22
|
+
#define DLLEXPORT
|
23
|
+
#endif
|
24
|
+
|
25
|
+
#ifndef S_ISREG
|
26
|
+
#define S_ISREG(m) (((m) & (_S_IFMT)) == (_S_IFREG))
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#ifndef O_ACCMODE
|
30
|
+
#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
|
31
|
+
#endif
|
32
|
+
|
33
|
+
#define INT2TIME(i) rb_funcall(rb_cTime, rb_intern("at"), 1, INT2NUM(i))
|
34
|
+
|
35
|
+
#define VERSION "0.1.0"
|
36
|
+
|
37
|
+
static VALUE Tar;
|
38
|
+
static VALUE Error;
|
39
|
+
|
40
|
+
struct tarruby_tar {
|
41
|
+
TAR *tar;
|
42
|
+
int extracted;
|
43
|
+
};
|
44
|
+
|
45
|
+
#ifdef HAVE_ZLIB_H
|
46
|
+
// copy from libtar.c
|
47
|
+
// Copyright 1998-2003 University of Illinois Board of Trustees
|
48
|
+
// Copyright 1998-2003 Mark D. Roth
|
49
|
+
static int gzopen_frontend(char *pathname, int oflags, int mode) {
|
50
|
+
char *gzoflags;
|
51
|
+
gzFile gzf;
|
52
|
+
#ifndef _WIN32
|
53
|
+
int fd;
|
54
|
+
#endif
|
55
|
+
|
56
|
+
switch (oflags & O_ACCMODE) {
|
57
|
+
case O_WRONLY:
|
58
|
+
gzoflags = "wb";
|
59
|
+
break;
|
60
|
+
|
61
|
+
case O_RDONLY:
|
62
|
+
gzoflags = "rb";
|
63
|
+
break;
|
64
|
+
|
65
|
+
default:
|
66
|
+
case O_RDWR:
|
67
|
+
errno = EINVAL;
|
68
|
+
return -1;
|
69
|
+
}
|
70
|
+
|
71
|
+
#ifndef _WIN32
|
72
|
+
fd = open(pathname, oflags, mode);
|
73
|
+
|
74
|
+
if (fd == -1) {
|
75
|
+
return -1;
|
76
|
+
}
|
77
|
+
|
78
|
+
if ((oflags & O_CREAT) && fchmod(fd, mode)) {
|
79
|
+
return -1;
|
80
|
+
}
|
81
|
+
|
82
|
+
gzf = gzdopen(fd, gzoflags);
|
83
|
+
#else
|
84
|
+
gzf = gzopen(pathname, gzoflags);
|
85
|
+
#endif
|
86
|
+
if (!gzf) {
|
87
|
+
errno = ENOMEM;
|
88
|
+
return -1;
|
89
|
+
}
|
90
|
+
|
91
|
+
return (int) gzf;
|
92
|
+
}
|
93
|
+
|
94
|
+
static tartype_t gztype = {
|
95
|
+
(openfunc_t) gzopen_frontend,
|
96
|
+
(closefunc_t) gzclose,
|
97
|
+
(readfunc_t) gzread,
|
98
|
+
(writefunc_t) gzwrite
|
99
|
+
};
|
100
|
+
#endif
|
101
|
+
|
102
|
+
#ifdef HAVE_BZLIB_H
|
103
|
+
static int bzopen_frontend(char *pathname, int oflags, int mode) {
|
104
|
+
char *bzoflags;
|
105
|
+
BZFILE *bzf;
|
106
|
+
#ifndef _WIN32
|
107
|
+
int fd;
|
108
|
+
#endif
|
109
|
+
|
110
|
+
switch (oflags & O_ACCMODE) {
|
111
|
+
case O_WRONLY:
|
112
|
+
bzoflags = "wb";
|
113
|
+
break;
|
114
|
+
|
115
|
+
case O_RDONLY:
|
116
|
+
bzoflags = "rb";
|
117
|
+
break;
|
118
|
+
|
119
|
+
default:
|
120
|
+
case O_RDWR:
|
121
|
+
errno = EINVAL;
|
122
|
+
return -1;
|
123
|
+
}
|
124
|
+
|
125
|
+
#ifndef _WIN32
|
126
|
+
fd = open(pathname, oflags, mode);
|
127
|
+
|
128
|
+
if (fd == -1) {
|
129
|
+
return -1;
|
130
|
+
}
|
131
|
+
|
132
|
+
if ((oflags & O_CREAT) && fchmod(fd, mode)) {
|
133
|
+
return -1;
|
134
|
+
}
|
135
|
+
|
136
|
+
bzf = BZ2_bzdopen(fd, bzoflags);
|
137
|
+
#else
|
138
|
+
bzf = BZ2_bzopen(pathname, bzoflags);
|
139
|
+
#endif
|
140
|
+
if (!bzf) {
|
141
|
+
errno = ENOMEM;
|
142
|
+
return -1;
|
143
|
+
}
|
144
|
+
|
145
|
+
return (int) bzf;
|
146
|
+
}
|
147
|
+
|
148
|
+
static tartype_t bztype = {
|
149
|
+
(openfunc_t) bzopen_frontend,
|
150
|
+
(closefunc_t) BZ2_bzclose,
|
151
|
+
(readfunc_t) BZ2_bzread,
|
152
|
+
(writefunc_t) BZ2_bzwrite
|
153
|
+
};
|
154
|
+
#endif
|
155
|
+
|
156
|
+
static VALUE tarruby_tar_alloc(VALUE klass) {
|
157
|
+
struct tarruby_tar *p = ALLOC(struct tarruby_tar);
|
158
|
+
|
159
|
+
p->tar = NULL;
|
160
|
+
p->extracted = 1;
|
161
|
+
|
162
|
+
return Data_Wrap_Struct(klass, 0, -1, p);
|
163
|
+
}
|
164
|
+
|
165
|
+
/* */
|
166
|
+
static VALUE tarruby_close(VALUE self) {
|
167
|
+
struct tarruby_tar *p_tar;
|
168
|
+
|
169
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
170
|
+
|
171
|
+
if(tar_close(p_tar->tar) != 0) {
|
172
|
+
rb_raise(Error, "Close archive failed");
|
173
|
+
}
|
174
|
+
|
175
|
+
return Qnil;
|
176
|
+
}
|
177
|
+
|
178
|
+
static VALUE tarruby_s_open0(int argc, VALUE *argv, VALUE self, tartype_t *tartype) {
|
179
|
+
VALUE tar, pathname, oflags, mode, options;
|
180
|
+
struct tarruby_tar *p_tar;
|
181
|
+
char *s_pathname;
|
182
|
+
int i_oflags, i_mode = 0644, i_options = 0;
|
183
|
+
|
184
|
+
rb_scan_args(argc, argv, "22", &pathname, &oflags, &mode, &options);
|
185
|
+
Check_Type(pathname, T_STRING);
|
186
|
+
s_pathname = RSTRING_PTR(pathname);
|
187
|
+
i_oflags = NUM2INT(oflags);
|
188
|
+
if (!NIL_P(mode)) { i_mode = NUM2INT(mode); }
|
189
|
+
if (!NIL_P(options)) { i_options = NUM2INT(options); }
|
190
|
+
|
191
|
+
tar = rb_funcall(Tar, rb_intern("new"), 0);
|
192
|
+
Data_Get_Struct(tar, struct tarruby_tar, p_tar);
|
193
|
+
|
194
|
+
if (tar_open(&p_tar->tar, s_pathname, tartype, i_oflags, i_mode, i_options) == -1) {
|
195
|
+
rb_raise(Error, "Open archive failed");
|
196
|
+
}
|
197
|
+
|
198
|
+
if (rb_block_given_p()) {
|
199
|
+
VALUE retval;
|
200
|
+
int status;
|
201
|
+
|
202
|
+
retval = rb_protect(rb_yield, tar, &status);
|
203
|
+
tarruby_close(tar);
|
204
|
+
|
205
|
+
if (status != 0) {
|
206
|
+
rb_jump_tag(status);
|
207
|
+
}
|
208
|
+
|
209
|
+
return retval;
|
210
|
+
} else {
|
211
|
+
return tar;
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
/* */
|
216
|
+
static VALUE tarruby_s_open(int argc, VALUE *argv, VALUE self) {
|
217
|
+
return tarruby_s_open0(argc, argv, self, NULL);
|
218
|
+
}
|
219
|
+
|
220
|
+
#ifdef HAVE_ZLIB_H
|
221
|
+
/* */
|
222
|
+
static VALUE tarruby_s_gzopen(int argc, VALUE *argv, VALUE self) {
|
223
|
+
return tarruby_s_open0(argc, argv, self, &gztype);
|
224
|
+
}
|
225
|
+
#endif
|
226
|
+
|
227
|
+
#ifdef HAVE_BZLIB_H
|
228
|
+
/* */
|
229
|
+
static VALUE tarruby_s_bzopen(int argc, VALUE *argv, VALUE self) {
|
230
|
+
return tarruby_s_open0(argc, argv, self, &bztype);
|
231
|
+
}
|
232
|
+
#endif
|
233
|
+
|
234
|
+
/* */
|
235
|
+
static VALUE tarruby_append_file(int argc, VALUE *argv, VALUE self) {
|
236
|
+
VALUE realname, savename;
|
237
|
+
struct tarruby_tar *p_tar;
|
238
|
+
char *s_realname, *s_savename = NULL;
|
239
|
+
|
240
|
+
rb_scan_args(argc, argv, "11", &realname, &savename);
|
241
|
+
Check_Type(realname, T_STRING);
|
242
|
+
s_realname = RSTRING_PTR(realname);
|
243
|
+
|
244
|
+
if (!NIL_P(savename)) {
|
245
|
+
Check_Type(savename, T_STRING);
|
246
|
+
s_savename = RSTRING_PTR(savename);
|
247
|
+
}
|
248
|
+
|
249
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
250
|
+
|
251
|
+
if (tar_append_file(p_tar->tar, s_realname, s_savename) != 0) {
|
252
|
+
rb_raise(Error, "Append file failed");
|
253
|
+
}
|
254
|
+
|
255
|
+
return Qnil;
|
256
|
+
}
|
257
|
+
|
258
|
+
/* */
|
259
|
+
static VALUE tarruby_append_tree(int argc, VALUE *argv, VALUE self) {
|
260
|
+
VALUE realdir, savedir;
|
261
|
+
struct tarruby_tar *p_tar;
|
262
|
+
char *s_realdir, *s_savedir = NULL;
|
263
|
+
|
264
|
+
rb_scan_args(argc, argv, "11", &realdir, &savedir);
|
265
|
+
Check_Type(realdir, T_STRING);
|
266
|
+
s_realdir = RSTRING_PTR(realdir);
|
267
|
+
|
268
|
+
if (!NIL_P(savedir)) {
|
269
|
+
Check_Type(savedir, T_STRING);
|
270
|
+
s_savedir = RSTRING_PTR(savedir);
|
271
|
+
}
|
272
|
+
|
273
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
274
|
+
|
275
|
+
if (tar_append_tree(p_tar->tar, s_realdir, s_savedir) != 0) {
|
276
|
+
rb_raise(Error, "Append tree failed");
|
277
|
+
}
|
278
|
+
|
279
|
+
return Qnil;
|
280
|
+
}
|
281
|
+
|
282
|
+
/* */
|
283
|
+
static VALUE tarruby_extract_file(VALUE self, VALUE realname) {
|
284
|
+
struct tarruby_tar *p_tar;
|
285
|
+
char *s_realname;
|
286
|
+
|
287
|
+
Check_Type(realname, T_STRING);
|
288
|
+
s_realname = RSTRING_PTR(realname);
|
289
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
290
|
+
|
291
|
+
if (tar_extract_file(p_tar->tar, s_realname) != 0) {
|
292
|
+
rb_raise(Error, "Extract file failed");
|
293
|
+
}
|
294
|
+
|
295
|
+
p_tar->extracted = 1;
|
296
|
+
|
297
|
+
return Qnil;
|
298
|
+
}
|
299
|
+
|
300
|
+
static int tarruby_extract_buffer0(char *buf, int len, void *data) {
|
301
|
+
VALUE buffer = (VALUE) data;
|
302
|
+
rb_str_buf_cat(buffer, buf, len);
|
303
|
+
return 0;
|
304
|
+
}
|
305
|
+
|
306
|
+
/* */
|
307
|
+
static VALUE tarruby_extract_buffer(VALUE self) {
|
308
|
+
VALUE buffer;
|
309
|
+
struct tarruby_tar *p_tar;
|
310
|
+
int i;
|
311
|
+
|
312
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
313
|
+
buffer = rb_str_new("", 0);
|
314
|
+
|
315
|
+
if ((i = tar_extract_function(p_tar->tar, (void *) buffer, tarruby_extract_buffer0)) == -1) {
|
316
|
+
rb_raise(Error, "Extract buffer failed");
|
317
|
+
}
|
318
|
+
|
319
|
+
p_tar->extracted = 1;
|
320
|
+
|
321
|
+
return (i == 0) ? buffer : Qnil;
|
322
|
+
}
|
323
|
+
|
324
|
+
/* */
|
325
|
+
static VALUE tarruby_extract_glob(int argc, VALUE *argv, VALUE self) {
|
326
|
+
VALUE globname, prefix;
|
327
|
+
struct tarruby_tar *p_tar;
|
328
|
+
char *s_globname, *s_prefix = NULL;
|
329
|
+
|
330
|
+
rb_scan_args(argc, argv, "11", &globname, &prefix);
|
331
|
+
Check_Type(globname, T_STRING);
|
332
|
+
s_globname = RSTRING_PTR(globname);
|
333
|
+
|
334
|
+
if (!NIL_P(prefix)) {
|
335
|
+
Check_Type(prefix, T_STRING);
|
336
|
+
s_prefix = RSTRING_PTR(prefix);
|
337
|
+
}
|
338
|
+
|
339
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
340
|
+
|
341
|
+
if (tar_extract_glob(p_tar->tar, s_globname, s_prefix) != 0) {
|
342
|
+
rb_raise(Error, "Extract archive failed");
|
343
|
+
}
|
344
|
+
|
345
|
+
p_tar->extracted = 1;
|
346
|
+
|
347
|
+
return Qnil;
|
348
|
+
}
|
349
|
+
|
350
|
+
/* */
|
351
|
+
static VALUE tarruby_extract_all(int argc, VALUE *argv, VALUE self) {
|
352
|
+
VALUE prefix;
|
353
|
+
struct tarruby_tar *p_tar;
|
354
|
+
char *s_prefix = NULL;
|
355
|
+
|
356
|
+
rb_scan_args(argc, argv, "01", &prefix);
|
357
|
+
|
358
|
+
if (!NIL_P(prefix)) {
|
359
|
+
Check_Type(prefix, T_STRING);
|
360
|
+
s_prefix = RSTRING_PTR(prefix);
|
361
|
+
}
|
362
|
+
|
363
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
364
|
+
|
365
|
+
if (tar_extract_all(p_tar->tar, s_prefix) != 0) {
|
366
|
+
rb_raise(Error, "Extract archive failed");
|
367
|
+
}
|
368
|
+
|
369
|
+
p_tar->extracted = 1;
|
370
|
+
|
371
|
+
return Qnil;
|
372
|
+
}
|
373
|
+
|
374
|
+
static void tarruby_skip_regfile_if_not_extracted(struct tarruby_tar *p) {
|
375
|
+
if (!p->extracted) {
|
376
|
+
if (TH_ISREG(p->tar) && tar_skip_regfile(p->tar) != 0) {
|
377
|
+
rb_raise(Error, "Read archive failed");
|
378
|
+
}
|
379
|
+
|
380
|
+
p->extracted = 1;
|
381
|
+
}
|
382
|
+
}
|
383
|
+
|
384
|
+
/* */
|
385
|
+
static VALUE tarruby_read(VALUE self) {
|
386
|
+
struct tarruby_tar *p_tar;
|
387
|
+
int i;
|
388
|
+
|
389
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
390
|
+
tarruby_skip_regfile_if_not_extracted(p_tar);
|
391
|
+
|
392
|
+
if ((i = th_read(p_tar->tar)) == -1) {
|
393
|
+
rb_raise(Error, "Read archive failed");
|
394
|
+
}
|
395
|
+
|
396
|
+
p_tar->extracted = 0;
|
397
|
+
|
398
|
+
return (i == 0) ? Qtrue : Qfalse;
|
399
|
+
}
|
400
|
+
|
401
|
+
/* */
|
402
|
+
static VALUE tarruby_each(VALUE self) {
|
403
|
+
struct tarruby_tar *p_tar;
|
404
|
+
int i;
|
405
|
+
|
406
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
407
|
+
tarruby_skip_regfile_if_not_extracted(p_tar);
|
408
|
+
|
409
|
+
while ((i = th_read(p_tar->tar)) == 0) {
|
410
|
+
p_tar->extracted = 0;
|
411
|
+
rb_yield(self);
|
412
|
+
tarruby_skip_regfile_if_not_extracted(p_tar);
|
413
|
+
}
|
414
|
+
|
415
|
+
if (i == -1) {
|
416
|
+
rb_raise(Error, "Read archive failed");
|
417
|
+
}
|
418
|
+
|
419
|
+
return Qnil;
|
420
|
+
}
|
421
|
+
|
422
|
+
/* */
|
423
|
+
static VALUE tarruby_crc(VALUE self) {
|
424
|
+
struct tarruby_tar *p_tar;
|
425
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
426
|
+
return INT2NUM(th_get_crc(p_tar->tar));
|
427
|
+
}
|
428
|
+
|
429
|
+
/* */
|
430
|
+
static VALUE tarruby_size(VALUE self) {
|
431
|
+
struct tarruby_tar *p_tar;
|
432
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
433
|
+
return INT2NUM(th_get_size(p_tar->tar));
|
434
|
+
}
|
435
|
+
|
436
|
+
/* */
|
437
|
+
static VALUE tarruby_mtime(VALUE self) {
|
438
|
+
struct tarruby_tar *p_tar;
|
439
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
440
|
+
return INT2TIME(th_get_mtime(p_tar->tar));
|
441
|
+
}
|
442
|
+
|
443
|
+
/* */
|
444
|
+
static VALUE tarruby_devmajor(VALUE self) {
|
445
|
+
struct tarruby_tar *p_tar;
|
446
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
447
|
+
return INT2NUM(th_get_devmajor(p_tar->tar));
|
448
|
+
}
|
449
|
+
|
450
|
+
/* */
|
451
|
+
static VALUE tarruby_devminor(VALUE self) {
|
452
|
+
struct tarruby_tar *p_tar;
|
453
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
454
|
+
return INT2NUM(th_get_devminor(p_tar->tar));
|
455
|
+
}
|
456
|
+
|
457
|
+
/* */
|
458
|
+
static VALUE tarruby_linkname(VALUE self) {
|
459
|
+
struct tarruby_tar *p_tar;
|
460
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
461
|
+
return rb_str_new2(th_get_linkname(p_tar->tar));
|
462
|
+
}
|
463
|
+
|
464
|
+
/* */
|
465
|
+
static VALUE tarruby_pathname(VALUE self) {
|
466
|
+
struct tarruby_tar *p_tar;
|
467
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
468
|
+
return rb_str_new2(th_get_pathname(p_tar->tar));
|
469
|
+
}
|
470
|
+
|
471
|
+
/* */
|
472
|
+
static VALUE tarruby_mode(VALUE self) {
|
473
|
+
struct tarruby_tar *p_tar;
|
474
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
475
|
+
return LONG2NUM(th_get_mode(p_tar->tar));
|
476
|
+
}
|
477
|
+
|
478
|
+
/* */
|
479
|
+
static VALUE tarruby_uid(VALUE self) {
|
480
|
+
struct tarruby_tar *p_tar;
|
481
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
482
|
+
return LONG2NUM(th_get_uid(p_tar->tar));
|
483
|
+
}
|
484
|
+
|
485
|
+
/* */
|
486
|
+
static VALUE tarruby_gid(VALUE self) {
|
487
|
+
struct tarruby_tar *p_tar;
|
488
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
489
|
+
return LONG2NUM(th_get_gid(p_tar->tar));
|
490
|
+
}
|
491
|
+
|
492
|
+
/* */
|
493
|
+
static VALUE tarruby_print(VALUE self) {
|
494
|
+
struct tarruby_tar *p_tar;
|
495
|
+
|
496
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
497
|
+
th_print(p_tar->tar);
|
498
|
+
|
499
|
+
return Qnil;
|
500
|
+
}
|
501
|
+
|
502
|
+
/* */
|
503
|
+
static VALUE tarruby_print_long_ls(VALUE self) {
|
504
|
+
struct tarruby_tar *p_tar;
|
505
|
+
|
506
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
507
|
+
th_print_long_ls(p_tar->tar);
|
508
|
+
|
509
|
+
return Qnil;
|
510
|
+
}
|
511
|
+
|
512
|
+
/* */
|
513
|
+
static VALUE tarruby_is_reg(VALUE self) {
|
514
|
+
struct tarruby_tar *p_tar;
|
515
|
+
|
516
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
517
|
+
|
518
|
+
return TH_ISREG(p_tar->tar) ? Qtrue : Qfalse;
|
519
|
+
}
|
520
|
+
|
521
|
+
/* */
|
522
|
+
static VALUE tarruby_is_lnk(VALUE self) {
|
523
|
+
struct tarruby_tar *p_tar;
|
524
|
+
|
525
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
526
|
+
|
527
|
+
return TH_ISLNK(p_tar->tar) ? Qtrue : Qfalse;
|
528
|
+
}
|
529
|
+
|
530
|
+
/* */
|
531
|
+
static VALUE tarruby_is_sym(VALUE self) {
|
532
|
+
struct tarruby_tar *p_tar;
|
533
|
+
|
534
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
535
|
+
|
536
|
+
return TH_ISSYM(p_tar->tar) ? Qtrue : Qfalse;
|
537
|
+
}
|
538
|
+
|
539
|
+
/* */
|
540
|
+
static VALUE tarruby_is_chr(VALUE self) {
|
541
|
+
struct tarruby_tar *p_tar;
|
542
|
+
|
543
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
544
|
+
|
545
|
+
return TH_ISCHR(p_tar->tar) ? Qtrue : Qfalse;
|
546
|
+
}
|
547
|
+
|
548
|
+
/* */
|
549
|
+
static VALUE tarruby_is_blk(VALUE self) {
|
550
|
+
struct tarruby_tar *p_tar;
|
551
|
+
|
552
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
553
|
+
|
554
|
+
return TH_ISBLK(p_tar->tar) ? Qtrue : Qfalse;
|
555
|
+
}
|
556
|
+
|
557
|
+
/* */
|
558
|
+
static VALUE tarruby_is_dir(VALUE self) {
|
559
|
+
struct tarruby_tar *p_tar;
|
560
|
+
|
561
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
562
|
+
|
563
|
+
return TH_ISDIR(p_tar->tar) ? Qtrue : Qfalse;
|
564
|
+
}
|
565
|
+
|
566
|
+
/* */
|
567
|
+
static VALUE tarruby_is_fifo(VALUE self) {
|
568
|
+
struct tarruby_tar *p_tar;
|
569
|
+
|
570
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
571
|
+
|
572
|
+
return TH_ISFIFO(p_tar->tar) ? Qtrue : Qfalse;
|
573
|
+
}
|
574
|
+
|
575
|
+
/* */
|
576
|
+
static VALUE tarruby_is_longname(VALUE self) {
|
577
|
+
struct tarruby_tar *p_tar;
|
578
|
+
|
579
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
580
|
+
|
581
|
+
return TH_ISLONGNAME(p_tar->tar) ? Qtrue : Qfalse;
|
582
|
+
}
|
583
|
+
|
584
|
+
/* */
|
585
|
+
static VALUE tarruby_is_longlink(VALUE self) {
|
586
|
+
struct tarruby_tar *p_tar;
|
587
|
+
|
588
|
+
Data_Get_Struct(self, struct tarruby_tar, p_tar);
|
589
|
+
|
590
|
+
return TH_ISLONGLINK(p_tar->tar) ? Qtrue : Qfalse;
|
591
|
+
}
|
592
|
+
|
593
|
+
void DLLEXPORT Init_tarruby() {
|
594
|
+
Tar = rb_define_class("Tar", rb_cObject);
|
595
|
+
rb_define_alloc_func(Tar, tarruby_tar_alloc);
|
596
|
+
rb_include_module(Tar, rb_mEnumerable);
|
597
|
+
rb_funcall(Tar, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("new")));
|
598
|
+
|
599
|
+
Error = rb_define_class_under(Tar, "Error", rb_eStandardError);
|
600
|
+
|
601
|
+
rb_define_const(Tar, "VERSION", rb_str_new2(VERSION));
|
602
|
+
|
603
|
+
rb_define_const(Tar, "GNU", INT2NUM(TAR_GNU)); /* use GNU extensions */
|
604
|
+
rb_define_const(Tar, "VERBOSE", INT2NUM(TAR_VERBOSE)); /* output file info to stdout */
|
605
|
+
rb_define_const(Tar, "NOOVERWRITE", INT2NUM(TAR_NOOVERWRITE)); /* don't overwrite existing files */
|
606
|
+
rb_define_const(Tar, "IGNORE_EOT", INT2NUM(TAR_IGNORE_EOT)); /* ignore double zero blocks as EOF */
|
607
|
+
rb_define_const(Tar, "CHECK_MAGIC", INT2NUM(TAR_CHECK_MAGIC)); /* check magic in file header */
|
608
|
+
rb_define_const(Tar, "CHECK_VERSION", INT2NUM(TAR_CHECK_VERSION)); /* check version in file header */
|
609
|
+
rb_define_const(Tar, "IGNORE_CRC", INT2NUM(TAR_IGNORE_CRC)); /* ignore CRC in file header */
|
610
|
+
|
611
|
+
rb_define_singleton_method(Tar, "open", tarruby_s_open, -1);
|
612
|
+
#ifdef HAVE_ZLIB_H
|
613
|
+
rb_define_singleton_method(Tar, "gzopen", tarruby_s_gzopen, -1);
|
614
|
+
#endif
|
615
|
+
#ifdef HAVE_BZLIB_H
|
616
|
+
rb_define_singleton_method(Tar, "bzopen", tarruby_s_bzopen, -1);
|
617
|
+
#endif
|
618
|
+
rb_define_method(Tar, "close", tarruby_close, 0);
|
619
|
+
rb_define_method(Tar, "append_file", tarruby_append_file, -1);
|
620
|
+
rb_define_method(Tar, "append_tree", tarruby_append_tree, -1);
|
621
|
+
rb_define_method(Tar, "extract_file", tarruby_extract_file, 1);
|
622
|
+
rb_define_method(Tar, "extract_buffer", tarruby_extract_buffer, 0);
|
623
|
+
rb_define_method(Tar, "extract_glob", tarruby_extract_glob, -1);
|
624
|
+
rb_define_method(Tar, "extract_all", tarruby_extract_all, -1);
|
625
|
+
rb_define_method(Tar, "read", tarruby_read, 0);
|
626
|
+
rb_define_method(Tar, "each", tarruby_each, 0);
|
627
|
+
rb_define_method(Tar, "crc", tarruby_crc, 0);
|
628
|
+
rb_define_method(Tar, "size", tarruby_size, 0);
|
629
|
+
rb_define_method(Tar, "mtime", tarruby_mtime, 0);
|
630
|
+
rb_define_method(Tar, "devmajor", tarruby_devmajor, 0);
|
631
|
+
rb_define_method(Tar, "devminor", tarruby_devminor, 0);
|
632
|
+
rb_define_method(Tar, "linkname", tarruby_linkname, 0);
|
633
|
+
rb_define_method(Tar, "pathname", tarruby_pathname, 0);
|
634
|
+
rb_define_method(Tar, "mode", tarruby_mode, 0);
|
635
|
+
rb_define_method(Tar, "uid", tarruby_uid, 0);
|
636
|
+
rb_define_method(Tar, "gid", tarruby_gid, 0);
|
637
|
+
rb_define_method(Tar, "print", tarruby_print, 0);
|
638
|
+
rb_define_method(Tar, "print_long_ls", tarruby_print_long_ls, 0);
|
639
|
+
rb_define_method(Tar, "reg?", tarruby_is_reg, 0);
|
640
|
+
rb_define_method(Tar, "lnk?", tarruby_is_lnk, 0);
|
641
|
+
rb_define_method(Tar, "sym?", tarruby_is_sym, 0);
|
642
|
+
rb_define_method(Tar, "chr?", tarruby_is_chr, 0);
|
643
|
+
rb_define_method(Tar, "blk?", tarruby_is_blk, 0);
|
644
|
+
rb_define_method(Tar, "dir?", tarruby_is_dir, 0);
|
645
|
+
rb_define_method(Tar, "fifo?", tarruby_is_fifo, 0);
|
646
|
+
rb_define_method(Tar, "longname?", tarruby_is_longname, 0);
|
647
|
+
rb_define_method(Tar, "longlink?", tarruby_is_longlink, 0);
|
648
|
+
}
|