tarruby 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.txt CHANGED
@@ -21,7 +21,7 @@ gem install tarruby
21
21
 
22
22
  require 'tarruby'
23
23
 
24
- Tar.open('foo.tar', File::RDONLY, Tar::GNU) do |tar|
24
+ Tar.open('foo.tar', File::RDONLY, 0644, Tar::GNU | Tar::VERBOSE) do |tar|
25
25
  while tar.read # or 'tar.each do ...'
26
26
  puts tar.pathname
27
27
  tar.print_long_ls
@@ -48,7 +48,7 @@ gem install tarruby
48
48
 
49
49
  require 'tarruby'
50
50
 
51
- Tar.open('bar.tar', File::CREAT | File::WRONLY, Tar::GNU) do |tar|
51
+ Tar.open('bar.tar', File::CREAT | File::WRONLY, 0644, Tar::GNU | Tar::VERBOSE) do |tar|
52
52
  Dir.glob('**/*.c').each do |filename|
53
53
  tar.append_file(filename)
54
54
  end
@@ -16,7 +16,6 @@
16
16
  # include <libgen.h>
17
17
  #endif
18
18
 
19
-
20
19
  #if defined(NEED_BASENAME) && !defined(HAVE_BASENAME)
21
20
 
22
21
  # ifdef basename
@@ -83,6 +83,9 @@ openbsd_dirname(path)
83
83
  endp--;
84
84
  } while (endp > path && *endp == '/');
85
85
  #else
86
+ do {
87
+ endp--;
88
+ } while (endp > path && (*endp == '/' || *endp == '\\'));
86
89
  #endif
87
90
  }
88
91
 
@@ -52,6 +52,7 @@ tar_set_file_perms(TAR *t, char *realname)
52
52
  gid = th_get_gid(t);
53
53
  ut.modtime = ut.actime = th_get_mtime(t);
54
54
 
55
+ #ifndef _WIN32
55
56
  /* change owner/group */
56
57
  if (geteuid() == 0)
57
58
  #ifdef HAVE_LCHOWN
@@ -92,6 +93,7 @@ tar_set_file_perms(TAR *t, char *realname)
92
93
  if (!realname) free(filename);
93
94
  return -1;
94
95
  }
96
+ #endif
95
97
 
96
98
  if (!realname) free(filename);
97
99
  return 0;
@@ -43,4 +43,5 @@
43
43
  #define mknod(p, m, d) (0)
44
44
  #define snprintf(s, n, f, ...) do { _snprintf((s), (n), (f), __VA_ARGS__); (s)[(n) - 1] = '\0'; } while(0)
45
45
 
46
+ int tarruby_stat(const char *path, struct stat *buf);
46
47
  #endif
@@ -95,6 +95,13 @@ mkdirhier(char *path)
95
95
  if (*dirp == '\0')
96
96
  continue;
97
97
 
98
+ /*
99
+ * Don't try to build current or parent dir. It doesn't make sense anyhow,
100
+ * but it also returns EINVAL instead of EEXIST on BeOS!
101
+ */
102
+ if ((strcmp(dirp, ".") == 0) || (strcmp(dirp, "..") == 0))
103
+ continue;
104
+
98
105
  if (dst[0] != '\0')
99
106
  strcat(dst, "/");
100
107
  strcat(dst, dirp);
data/ext/tarruby.c CHANGED
@@ -32,7 +32,7 @@
32
32
 
33
33
  #define INT2TIME(i) rb_funcall(rb_cTime, rb_intern("at"), 1, INT2NUM(i))
34
34
 
35
- #define VERSION "0.1.1"
35
+ #define VERSION "0.1.2"
36
36
 
37
37
  static VALUE Tar;
38
38
  static VALUE Error;
@@ -153,6 +153,14 @@ static tartype_t bztype = {
153
153
  };
154
154
  #endif
155
155
 
156
+ static void strip_sep(char *path) {
157
+ int len = strlen(path);
158
+
159
+ if (path[len - 1] == '/' || path[len - 1] == '\\') {
160
+ path[len - 1] = '\0';
161
+ }
162
+ }
163
+
156
164
  static VALUE tarruby_tar_alloc(VALUE klass) {
157
165
  struct tarruby_tar *p = ALLOC(struct tarruby_tar);
158
166
 
@@ -163,18 +171,23 @@ static VALUE tarruby_tar_alloc(VALUE klass) {
163
171
  }
164
172
 
165
173
  /* */
166
- static VALUE tarruby_close(VALUE self) {
174
+ static VALUE tarruby_close0(VALUE self, int abort) {
167
175
  struct tarruby_tar *p_tar;
168
176
 
169
177
  Data_Get_Struct(self, struct tarruby_tar, p_tar);
170
178
 
171
- if(tar_close(p_tar->tar) != 0) {
179
+ if(tar_close(p_tar->tar) != 0 && abort) {
172
180
  rb_raise(Error, "Close archive failed: %s", strerror(errno));
173
181
  }
174
182
 
175
183
  return Qnil;
176
184
  }
177
185
 
186
+ /* */
187
+ static VALUE tarruby_close(VALUE self) {
188
+ return tarruby_close0(self, 1);
189
+ }
190
+
178
191
  static VALUE tarruby_s_open0(int argc, VALUE *argv, VALUE self, tartype_t *tartype) {
179
192
  VALUE tar, pathname, oflags, mode, options;
180
193
  struct tarruby_tar *p_tar;
@@ -200,7 +213,7 @@ static VALUE tarruby_s_open0(int argc, VALUE *argv, VALUE self, tartype_t *tarty
200
213
  int status;
201
214
 
202
215
  retval = rb_protect(rb_yield, tar, &status);
203
- tarruby_close(tar);
216
+ tarruby_close0(tar, 0);
204
217
 
205
218
  if (status != 0) {
206
219
  rb_jump_tag(status);
@@ -240,10 +253,12 @@ static VALUE tarruby_append_file(int argc, VALUE *argv, VALUE self) {
240
253
  rb_scan_args(argc, argv, "11", &realname, &savename);
241
254
  Check_Type(realname, T_STRING);
242
255
  s_realname = RSTRING_PTR(realname);
256
+ strip_sep(s_realname);
243
257
 
244
258
  if (!NIL_P(savename)) {
245
259
  Check_Type(savename, T_STRING);
246
260
  s_savename = RSTRING_PTR(savename);
261
+ strip_sep(s_savename);
247
262
  }
248
263
 
249
264
  Data_Get_Struct(self, struct tarruby_tar, p_tar);
@@ -264,10 +279,12 @@ static VALUE tarruby_append_tree(int argc, VALUE *argv, VALUE self) {
264
279
  rb_scan_args(argc, argv, "11", &realdir, &savedir);
265
280
  Check_Type(realdir, T_STRING);
266
281
  s_realdir = RSTRING_PTR(realdir);
282
+ strip_sep(s_realdir);
267
283
 
268
284
  if (!NIL_P(savedir)) {
269
285
  Check_Type(savedir, T_STRING);
270
286
  s_savedir = RSTRING_PTR(savedir);
287
+ strip_sep(s_savedir);
271
288
  }
272
289
 
273
290
  Data_Get_Struct(self, struct tarruby_tar, p_tar);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tarruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - winebarrel
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-11 00:00:00 +09:00
12
+ date: 2008-09-13 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15