libarchive-ruby-fs 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cad5ca6e728705a251de396e39cc0b704b8c14af
4
+ data.tar.gz: 466d30f2a49e7af1f622c7de19b3419291740882
5
+ SHA512:
6
+ metadata.gz: 1399659e2ae6a649edc6e8bad7dfff65015309fbf3dd9d4ed3c1c0a1723358adcf878b8d68db514fa4bf046c4da3a95d68b2032644d85a66f7710a8744e8c60e
7
+ data.tar.gz: 941744ac5459dcc17afd503354f306acba6522c1756d3bdb27ba8b1ecb8bca7e72a6570790e23e10286d698565603f80680badb30759ccf7ddd64100661cde0b
@@ -0,0 +1,31 @@
1
+ #include <errno.h>
2
+ #include <archive.h>
3
+
4
+ static struct {
5
+ int code;
6
+ int (*setter)(struct archive *);
7
+ } codes[] = {
8
+ { ARCHIVE_COMPRESSION_NONE, archive_read_support_compression_none },
9
+ { ARCHIVE_COMPRESSION_GZIP, archive_read_support_compression_gzip },
10
+ { ARCHIVE_COMPRESSION_BZIP2, archive_read_support_compression_bzip2 },
11
+ { ARCHIVE_COMPRESSION_COMPRESS, archive_read_support_compression_compress },
12
+ // XXX:
13
+ /*
14
+ { ARCHIVE_COMPRESSION_PROGRAM, archive_read_support_compression_program },
15
+ { ARCHIVE_COMPRESSION_LZMA, archive_read_support_compression_lzma },
16
+ */
17
+ { -1, NULL },
18
+ };
19
+
20
+ int archive_read_support_compression(struct archive *a, int code) {
21
+ int i;
22
+
23
+ for (i = 0; codes[i].code >= 0; i++) {
24
+ if (codes[i].code == code) {
25
+ return codes[i].setter(a);
26
+ }
27
+ }
28
+
29
+ archive_set_error(a, EINVAL, "No such compression");
30
+ return ARCHIVE_FATAL;
31
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef _ARCHIVE_READ_SUPPORT_COMPRESSION_H_
2
+ #define _ARCHIVE_READ_SUPPORT_COMPRESSION_H_
3
+
4
+ int archive_read_support_compression(struct archive *a, int code);
5
+
6
+ #endif
@@ -0,0 +1,32 @@
1
+ #include <errno.h>
2
+ #include <archive.h>
3
+
4
+ static struct {
5
+ int code;
6
+ int (*setter)(struct archive *);
7
+ } codes[] = {
8
+ { ARCHIVE_FORMAT_CPIO, archive_read_support_format_cpio },
9
+ { ARCHIVE_FORMAT_TAR, archive_read_support_format_tar },
10
+ { ARCHIVE_FORMAT_TAR_GNUTAR, archive_read_support_format_gnutar },
11
+ { ARCHIVE_FORMAT_ISO9660, archive_read_support_format_iso9660 },
12
+ { ARCHIVE_FORMAT_ZIP, archive_read_support_format_zip },
13
+ { ARCHIVE_FORMAT_EMPTY, archive_read_support_format_empty },
14
+ { ARCHIVE_FORMAT_AR, archive_read_support_format_ar },
15
+ #ifdef ARCHIVE_FORMAT_MTREE
16
+ { ARCHIVE_FORMAT_MTREE, archive_read_support_format_mtree },
17
+ #endif
18
+ { -1, NULL },
19
+ };
20
+
21
+ int archive_read_support_format(struct archive *a, int code) {
22
+ int i;
23
+
24
+ for (i = 0; codes[i].code >= 0; i++) {
25
+ if (codes[i].code == code) {
26
+ return codes[i].setter(a);
27
+ }
28
+ }
29
+
30
+ archive_set_error(a, EINVAL, "No such format");
31
+ return ARCHIVE_FATAL;
32
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef _ARCHIVE_READ_SUPPORT_FORMAT_H_
2
+ #define _ARCHIVE_READ_SUPPORT_FORMAT_H_
3
+
4
+ int archive_read_support_format(struct archive *a, int code);
5
+
6
+ #endif
@@ -0,0 +1,25 @@
1
+ #include <archive.h>
2
+ #include <ruby.h>
3
+
4
+ static int rb_str_write_open(struct archive *a, void *client_data) {
5
+ if (archive_write_get_bytes_in_last_block(a) == -1) {
6
+ archive_write_set_bytes_in_last_block(a, 1);
7
+ }
8
+
9
+ return ARCHIVE_OK;
10
+ }
11
+
12
+ static int rb_str_write_close(struct archive *a, void *client_data) {
13
+ return ARCHIVE_OK;
14
+ }
15
+
16
+
17
+ static ssize_t rb_str_write(struct archive *a, void *client_data, const void *buff, size_t length) {
18
+ VALUE str = (VALUE) client_data;
19
+ rb_str_cat(str, buff, length);
20
+ return length;
21
+ }
22
+
23
+ int archive_write_open_rb_str(struct archive *a, VALUE str) {
24
+ return archive_write_open(a, (void *) str, rb_str_write_open, rb_str_write, rb_str_write_close);
25
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef _ARCHIVE_WRITE_OPEN_RB_STR_H_
2
+ #define _ARCHIVE_WRITE_OPEN_RB_STR_H_
3
+
4
+ int archive_write_open_rb_str(struct archive *a, VALUE str);
5
+
6
+ #endif
@@ -0,0 +1,32 @@
1
+ #include <errno.h>
2
+ #include <archive.h>
3
+
4
+ static struct {
5
+ int code;
6
+ int (*setter)(struct archive *);
7
+ } codes[] = {
8
+ { ARCHIVE_COMPRESSION_NONE, archive_write_set_compression_none },
9
+ { ARCHIVE_COMPRESSION_GZIP, archive_write_set_compression_gzip },
10
+ { ARCHIVE_COMPRESSION_BZIP2, archive_write_set_compression_bzip2 },
11
+ #if ARCHIVE_VERSION_NUMBER >= 2005000
12
+ { ARCHIVE_COMPRESSION_COMPRESS, archive_write_set_compression_compress },
13
+ #endif
14
+ // XXX:
15
+ /*
16
+ { ARCHIVE_COMPRESSION_PROGRAM, archive_read_support_compression_program },
17
+ */
18
+ { -1, NULL },
19
+ };
20
+
21
+ int archive_write_set_compression(struct archive *a, int code) {
22
+ int i;
23
+
24
+ for (i = 0; codes[i].code >= 0; i++) {
25
+ if (codes[i].code == code) {
26
+ return codes[i].setter(a);
27
+ }
28
+ }
29
+
30
+ archive_set_error(a, EINVAL, "No such compression");
31
+ return ARCHIVE_FATAL;
32
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef _ARCHIVE_WRITE_SET_COMPRESSION_H_
2
+ #define _ARCHIVE_WRITE_SET_COMPRESSION_H_
3
+
4
+ int archive_write_set_compression(struct archive *a, int code);
5
+
6
+ #endif
@@ -0,0 +1,20 @@
1
+ require 'mkmf'
2
+
3
+ unless (libarchive_cfg = pkg_config('libarchive'))
4
+ abort 'Failed to locate pkg-config file for libarchive.'
5
+ end
6
+
7
+ unless have_library('archive')
8
+ abort 'Failed to test-link against libarchive.'
9
+ end
10
+
11
+ non_std_location = libarchive_cfg.detect { |flag| flag =~ /^-L/ }
12
+ if non_std_location
13
+ non_std_location.gsub!('-L', '')
14
+ $LDFLAGS << " -Wl,-rpath,#{non_std_location}"
15
+ message "embedding path to library into rblibarchive.so: #{non_std_location}\n"
16
+ end
17
+
18
+ with_cppflags("#{(libarchive_cfg.detect { |flag| flag =~ /^-I/ })}") do
19
+ create_makefile('rblibarchive')
20
+ end
@@ -0,0 +1,92 @@
1
+ #include "libarchive_internal.h"
2
+
3
+ VALUE rb_mArchive;
4
+ VALUE rb_eArchiveError;
5
+
6
+ /* */
7
+ VALUE rb_libarchive_s_version_number(VALUE self) {
8
+ #if ARCHIVE_VERSION >= 2005000
9
+ return INT2NUM(archive_version_number());
10
+ #else
11
+ return INT2NUM(archive_version_stamp());
12
+ #endif
13
+ }
14
+
15
+ /* */
16
+ VALUE rb_libarchive_s_version_string(VALUE self) {
17
+ #if ARCHIVE_VERSION_NUMBER >= 2005000
18
+ return rb_str_new2(archive_version_string());
19
+ #else
20
+ return rb_str_new2(archive_version());
21
+ #endif
22
+ }
23
+
24
+ void DLLEXPORT Init_rblibarchive() {
25
+ rb_mArchive = rb_define_module("LibArchiveRubyFs");
26
+
27
+ rb_define_const(rb_mArchive, "COMPRESSION_NONE", INT2NUM(ARCHIVE_COMPRESSION_NONE));
28
+ #ifdef HAVE_ZLIB_H
29
+ rb_define_const(rb_mArchive, "COMPRESSION_GZIP", INT2NUM(ARCHIVE_COMPRESSION_GZIP));
30
+ #endif
31
+ #ifdef HAVE_BZLIB_H
32
+ rb_define_const(rb_mArchive, "COMPRESSION_BZIP2", INT2NUM(ARCHIVE_COMPRESSION_BZIP2));
33
+ #endif
34
+ rb_define_const(rb_mArchive, "COMPRESSION_COMPRESS", INT2NUM(ARCHIVE_COMPRESSION_COMPRESS));
35
+ // XXX:
36
+ /*
37
+ rb_define_const(rb_mArchive, "COMPRESSION_PROGRAM", INT2NUM(ARCHIVE_COMPRESSION_PROGRAM));
38
+ rb_define_const(rb_mArchive, "COMPRESSION_LZMA", INT2NUM(ARCHIVE_COMPRESSION_LZMA));
39
+ */
40
+
41
+ rb_define_const(rb_mArchive, "FORMAT_BASE_MASK", INT2NUM(ARCHIVE_FORMAT_BASE_MASK));
42
+ rb_define_const(rb_mArchive, "FORMAT_CPIO", INT2NUM(ARCHIVE_FORMAT_CPIO));
43
+ rb_define_const(rb_mArchive, "FORMAT_CPIO_POSIX", INT2NUM(ARCHIVE_FORMAT_CPIO_POSIX));
44
+ rb_define_const(rb_mArchive, "FORMAT_CPIO_BIN_LE", INT2NUM(ARCHIVE_FORMAT_CPIO_BIN_LE));
45
+ rb_define_const(rb_mArchive, "FORMAT_CPIO_BIN_BE", INT2NUM(ARCHIVE_FORMAT_CPIO_BIN_BE));
46
+ rb_define_const(rb_mArchive, "FORMAT_CPIO_SVR4_NOCRC", INT2NUM(ARCHIVE_FORMAT_CPIO_SVR4_NOCRC));
47
+ rb_define_const(rb_mArchive, "FORMAT_CPIO_SVR4_CRC", INT2NUM(ARCHIVE_FORMAT_CPIO_SVR4_CRC));
48
+ rb_define_const(rb_mArchive, "FORMAT_SHAR", INT2NUM(ARCHIVE_FORMAT_SHAR));
49
+ rb_define_const(rb_mArchive, "FORMAT_SHAR_BASE", INT2NUM(ARCHIVE_FORMAT_SHAR_BASE));
50
+ rb_define_const(rb_mArchive, "FORMAT_SHAR_DUMP", INT2NUM(ARCHIVE_FORMAT_SHAR_DUMP));
51
+ rb_define_const(rb_mArchive, "FORMAT_TAR", INT2NUM(ARCHIVE_FORMAT_TAR));
52
+ rb_define_const(rb_mArchive, "FORMAT_TAR_USTAR", INT2NUM(ARCHIVE_FORMAT_TAR_USTAR));
53
+ rb_define_const(rb_mArchive, "FORMAT_TAR_PAX_INTERCHANGE", INT2NUM(ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE));
54
+ rb_define_const(rb_mArchive, "FORMAT_TAR_PAX_RESTRICTED", INT2NUM(ARCHIVE_FORMAT_TAR_PAX_RESTRICTED));
55
+ rb_define_const(rb_mArchive, "FORMAT_TAR_GNUTAR", INT2NUM(ARCHIVE_FORMAT_TAR_GNUTAR));
56
+ rb_define_const(rb_mArchive, "FORMAT_ISO9660", INT2NUM(ARCHIVE_FORMAT_ISO9660));
57
+ rb_define_const(rb_mArchive, "FORMAT_ISO9660_ROCKRIDGE", INT2NUM(ARCHIVE_FORMAT_ISO9660_ROCKRIDGE));
58
+ rb_define_const(rb_mArchive, "FORMAT_ZIP", INT2NUM(ARCHIVE_FORMAT_ZIP));
59
+ rb_define_const(rb_mArchive, "FORMAT_EMPTY", INT2NUM(ARCHIVE_FORMAT_EMPTY));
60
+ rb_define_const(rb_mArchive, "FORMAT_AR", INT2NUM(ARCHIVE_FORMAT_AR));
61
+ rb_define_const(rb_mArchive, "FORMAT_AR_GNU", INT2NUM(ARCHIVE_FORMAT_AR_GNU));
62
+ rb_define_const(rb_mArchive, "FORMAT_AR_BSD", INT2NUM(ARCHIVE_FORMAT_AR_BSD));
63
+ #ifdef ARCHIVE_FORMAT_MTREE
64
+ rb_define_const(rb_mArchive, "FORMAT_MTREE", INT2NUM(ARCHIVE_FORMAT_MTREE));
65
+ #endif
66
+
67
+ rb_define_const(rb_mArchive, "EXTRACT_OWNER", INT2NUM(ARCHIVE_EXTRACT_OWNER));
68
+ rb_define_const(rb_mArchive, "EXTRACT_PERM", INT2NUM(ARCHIVE_EXTRACT_PERM));
69
+ rb_define_const(rb_mArchive, "EXTRACT_TIME", INT2NUM(ARCHIVE_EXTRACT_TIME));
70
+ rb_define_const(rb_mArchive, "EXTRACT_NO_OVERWRITE", INT2NUM(ARCHIVE_EXTRACT_NO_OVERWRITE));
71
+ rb_define_const(rb_mArchive, "EXTRACT_UNLINK", INT2NUM(ARCHIVE_EXTRACT_UNLINK));
72
+ rb_define_const(rb_mArchive, "EXTRACT_ACL", INT2NUM(ARCHIVE_EXTRACT_ACL));
73
+ rb_define_const(rb_mArchive, "EXTRACT_FFLAGS", INT2NUM(ARCHIVE_EXTRACT_FFLAGS));
74
+ rb_define_const(rb_mArchive, "EXTRACT_XATTR", INT2NUM(ARCHIVE_EXTRACT_XATTR));
75
+ rb_define_const(rb_mArchive, "EXTRACT_SECURE_SYMLINKS", INT2NUM(ARCHIVE_EXTRACT_SECURE_SYMLINKS));
76
+ rb_define_const(rb_mArchive, "EXTRACT_SECURE_NODOTDOT", INT2NUM(ARCHIVE_EXTRACT_SECURE_NODOTDOT));
77
+ rb_define_const(rb_mArchive, "EXTRACT_NO_AUTODIR", INT2NUM(ARCHIVE_EXTRACT_NO_AUTODIR));
78
+ rb_define_const(rb_mArchive, "EXTRACT_NO_OVERWRITE_NEWER", INT2NUM(ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER));
79
+ #ifdef ARCHIVE_EXTRACT_SPARSE
80
+ rb_define_const(rb_mArchive, "EXTRACT_SPARSE", INT2NUM(ARCHIVE_EXTRACT_SPARSE));
81
+ #endif
82
+
83
+ rb_define_module_function(rb_mArchive, "version_number", rb_libarchive_s_version_number, 0);
84
+ rb_define_module_function(rb_mArchive, "version_string", rb_libarchive_s_version_string, 0);
85
+
86
+ rb_eArchiveError = rb_define_class_under(rb_mArchive, "Error", rb_eStandardError);
87
+
88
+ Init_libarchive_reader();
89
+ Init_libarchive_writer();
90
+ Init_libarchive_archive();
91
+ Init_libarchive_entry();
92
+ }
@@ -0,0 +1,84 @@
1
+ #include "libarchive_internal.h"
2
+
3
+ extern VALUE rb_cArchiveReader;
4
+ extern VALUE rb_cArchiveWriter;
5
+ extern VALUE rb_eArchiveError;
6
+
7
+ static void rb_libarchive_archive_free(struct rb_libarchive_archive_container *p) {
8
+ xfree(p);
9
+ }
10
+
11
+ static void rb_libarchive_archive_mark(struct rb_libarchive_archive_container *p) {
12
+ rb_gc_mark(p->memory);
13
+ }
14
+
15
+ VALUE rb_libarchive_archive_alloc(VALUE klass) {
16
+ struct rb_libarchive_archive_container *p = ALLOC(struct rb_libarchive_archive_container);
17
+ p->ar = NULL;
18
+ p->eof = 0;
19
+ p->memory = Qnil;
20
+ return Data_Wrap_Struct(klass, rb_libarchive_archive_mark, rb_libarchive_archive_free, p);
21
+ }
22
+
23
+ /* */
24
+ static VALUE rb_libarchive_archive_position_compressed(VALUE self) {
25
+ struct rb_libarchive_archive_container *p;
26
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
27
+ Check_Archive(p);
28
+ return LONG2NUM(archive_position_compressed(p->ar));
29
+ }
30
+
31
+ /* */
32
+ static VALUE rb_libarchive_archive_position_uncompressed(VALUE self) {
33
+ struct rb_libarchive_archive_container *p;
34
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
35
+ Check_Archive(p);
36
+ return LONG2NUM(archive_position_uncompressed(p->ar));
37
+ }
38
+
39
+ /* */
40
+ static VALUE rb_libarchive_archive_compression_name(VALUE self) {
41
+ struct rb_libarchive_archive_container *p;
42
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
43
+ Check_Archive(p);
44
+ return rb_str_new2(archive_compression_name(p->ar));
45
+ }
46
+
47
+ /* */
48
+ static VALUE rb_libarchive_archive_compression(VALUE self) {
49
+ struct rb_libarchive_archive_container *p;
50
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
51
+ Check_Archive(p);
52
+ return INT2NUM(archive_compression(p->ar));
53
+ }
54
+
55
+ /* */
56
+ static VALUE rb_libarchive_archive_format_name(VALUE self) {
57
+ struct rb_libarchive_archive_container *p;
58
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
59
+ Check_Archive(p);
60
+ return rb_str_new2(archive_format_name(p->ar));
61
+ }
62
+
63
+ /* */
64
+ static VALUE rb_libarchive_archive_format(VALUE self) {
65
+ struct rb_libarchive_archive_container *p;
66
+ Data_Get_Struct(self, struct rb_libarchive_archive_container, p);
67
+ Check_Archive(p);
68
+ return NUM2INT(archive_format(p->ar));
69
+ }
70
+
71
+ void Init_libarchive_archive() {
72
+ rb_define_method(rb_cArchiveReader, "position_compressed", rb_libarchive_archive_position_compressed, 0);
73
+ rb_define_method(rb_cArchiveWriter, "position_compressed", rb_libarchive_archive_position_compressed, 0);
74
+ rb_define_method(rb_cArchiveReader, "position_uncompressed", rb_libarchive_archive_position_uncompressed, 0);
75
+ rb_define_method(rb_cArchiveWriter, "position_uncompressed", rb_libarchive_archive_position_uncompressed, 0);
76
+ rb_define_method(rb_cArchiveReader, "compression_name", rb_libarchive_archive_compression_name, 0);
77
+ rb_define_method(rb_cArchiveWriter, "compression_name", rb_libarchive_archive_compression_name, 0);
78
+ rb_define_method(rb_cArchiveReader, "compression", rb_libarchive_archive_compression, 0);
79
+ rb_define_method(rb_cArchiveWriter, "compression", rb_libarchive_archive_compression, 0);
80
+ rb_define_method(rb_cArchiveReader, "format_name", rb_libarchive_archive_format_name, 0);
81
+ rb_define_method(rb_cArchiveWriter, "format_name", rb_libarchive_archive_format_name, 0);
82
+ rb_define_method(rb_cArchiveReader, "format", rb_libarchive_archive_format, 0);
83
+ rb_define_method(rb_cArchiveWriter, "format", rb_libarchive_archive_format, 0);
84
+ }