libarchive-ruby 0.0.1.dev → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -1
- data/ext/archive.cpp +216 -40
- data/ext/entry.cpp +51 -25
- data/ext/main.hpp +12 -4
- metadata +7 -10
data/README.rdoc
CHANGED
@@ -93,9 +93,21 @@ current directory:
|
|
93
93
|
|
94
94
|
a = Archive.new("myarchive.tar.gz")
|
95
95
|
a << "a.rb" << "b.cpp" << "README.rdoc"
|
96
|
-
|
96
|
+
|
97
|
+
If you have more than one file to add you can use an Array:
|
98
|
+
|
99
|
+
a = Archive.new("myarchive.tar.gz")
|
100
|
+
a << ["a.rb", "b.cpp", "README.rdoc"]
|
101
|
+
|
102
|
+
You can manipulate the entry witch is added to the file:
|
103
|
+
|
104
|
+
a = Archive.new("myarchive.tar.gz")
|
105
|
+
a.add("a.rb") {|entry| entry.mtime = Time.now }
|
106
|
+
|
107
|
+
|
97
108
|
#Note how libarchive-ruby automatically picked up the archive format
|
98
109
|
#you wanted by examining the file extension:
|
110
|
+
a = Archive.new("myarchive.tar.gz")
|
99
111
|
puts a.format_name #=> POSIX ustar format
|
100
112
|
|
101
113
|
== Further reading
|
data/ext/archive.cpp
CHANGED
@@ -58,6 +58,16 @@ struct write_obj {
|
|
58
58
|
std::vector<std::string> *allbuff;
|
59
59
|
};
|
60
60
|
|
61
|
+
struct add_obj {
|
62
|
+
struct archive* archive;
|
63
|
+
struct archive* file;
|
64
|
+
struct archive_entry* entry;
|
65
|
+
std::vector<struct archive_entry *> *entries;
|
66
|
+
std::vector<std::string> *allbuff;
|
67
|
+
int fd;
|
68
|
+
VALUE obj;
|
69
|
+
};
|
70
|
+
|
61
71
|
|
62
72
|
VALUE Archive_read_block_ensure(struct archive * data)
|
63
73
|
{
|
@@ -124,6 +134,9 @@ void Archive_format_from_path(VALUE self,int &format,int &compression)
|
|
124
134
|
compression=ARCHIVE_COMPRESSION_BZIP2;
|
125
135
|
}else if(selfpath.substr(selfpath.length()-4).compare(".tar")==0)
|
126
136
|
format=ARCHIVE_FORMAT_TAR_USTAR;
|
137
|
+
}else{
|
138
|
+
format = _self->format;
|
139
|
+
compression = _self->compression;
|
127
140
|
}
|
128
141
|
}
|
129
142
|
if(format==ARCHIVE_FORMAT_TAR_GNUTAR)
|
@@ -210,6 +223,7 @@ int Archive_write_set_compression(struct archive *data,int compression)
|
|
210
223
|
* be guessed from the file extension. Possible formats are:
|
211
224
|
* * :ar
|
212
225
|
* * :tar
|
226
|
+
* * :pax
|
213
227
|
* * :xar
|
214
228
|
* * :zip
|
215
229
|
* [compression] Symbol inidicating the compression you want to use. If
|
@@ -235,6 +249,10 @@ VALUE Archive_initialize(int argc, VALUE *argv,VALUE self)
|
|
235
249
|
_self->fd = NUM2INT(rb_funcall(path,rb_intern("fileno"),0));
|
236
250
|
_self->type = archive_fd;
|
237
251
|
rb_scan_args(argc, argv, "21", &path,&r_format,&r_compression);
|
252
|
+
}else if(rb_obj_is_kind_of(path,rb_cInteger)){
|
253
|
+
_self->fd = NUM2INT(path);
|
254
|
+
_self->type = archive_fd;
|
255
|
+
rb_scan_args(argc, argv, "21", &path,&r_format,&r_compression);
|
238
256
|
}else if(rb_respond_to(path,rb_intern("read"))){
|
239
257
|
_self->ruby = path;
|
240
258
|
_self->type = archive_ruby;
|
@@ -260,6 +278,8 @@ VALUE Archive_initialize(int argc, VALUE *argv,VALUE self)
|
|
260
278
|
rb_raise(rb_eTypeError,"exepted Symbol");
|
261
279
|
if(SYM2ID(r_format) == rb_intern("tar"))
|
262
280
|
format = ARCHIVE_FORMAT_TAR_GNUTAR;
|
281
|
+
else if(SYM2ID(r_format) == rb_intern("pax"))
|
282
|
+
format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE;
|
263
283
|
else if(SYM2ID(r_format) == rb_intern("zip"))
|
264
284
|
format = ARCHIVE_FORMAT_ZIP;
|
265
285
|
else if(SYM2ID(r_format) == rb_intern("ar"))
|
@@ -991,10 +1011,169 @@ VALUE Archive_compression_name(VALUE self)
|
|
991
1011
|
return name ? rb_str_new2(name) : Qnil ;
|
992
1012
|
}
|
993
1013
|
|
1014
|
+
//key is the entry and val is
|
1015
|
+
|
1016
|
+
//TODO: hier nochmal ein ensure rein damit es das file wieder zu macht?
|
1017
|
+
int Archive_add_hash_block(VALUE key,VALUE val,struct add_obj *obj){
|
1018
|
+
char buff[8192];
|
1019
|
+
size_t bytes_read;
|
1020
|
+
int fd=-1;
|
1021
|
+
obj->file = archive_read_disk_new();
|
1022
|
+
archive_read_disk_set_standard_lookup(obj->file);
|
1023
|
+
struct archive_entry *entry = archive_entry_new();
|
1024
|
+
archive_entry_copy_pathname(entry, rb_string_value_cstr(&key));
|
1025
|
+
if(rb_obj_is_kind_of(val,rb_cFile)){
|
1026
|
+
VALUE pathname = rb_funcall(val,rb_intern("path"),0); //source path
|
1027
|
+
VALUE obj2 = rb_file_s_expand_path(1,&pathname);
|
1028
|
+
archive_entry_copy_sourcepath(entry, rb_string_value_cstr(&obj2));
|
1029
|
+
fd = NUM2INT(rb_funcall(val,rb_intern("fileno"),0));
|
1030
|
+
}else if(rb_obj_is_kind_of(val,rb_cIO)){
|
1031
|
+
fd = NUM2INT(rb_funcall(val,rb_intern("fileno"),0));
|
1032
|
+
}else if(rb_respond_to(val,rb_intern("read"))){
|
1033
|
+
//stringio has neigther path or fileno, so do nothing
|
1034
|
+
}else {
|
1035
|
+
VALUE obj2 = rb_file_s_expand_path(1,&val);
|
1036
|
+
archive_entry_copy_sourcepath(entry, rb_string_value_cstr(&obj2));
|
1037
|
+
fd = open(rb_string_value_cstr(&obj2), O_RDONLY);
|
1038
|
+
if (fd < 0) //TODO: add error
|
1039
|
+
return 0;
|
1040
|
+
}
|
1041
|
+
if(fd > 0)
|
1042
|
+
archive_read_disk_entry_from_file(obj->file, entry, fd, NULL);
|
1043
|
+
if(rb_block_given_p()){
|
1044
|
+
VALUE temp = wrap(entry);
|
1045
|
+
VALUE result = rb_yield(temp);
|
1046
|
+
if(rb_obj_is_kind_of(result,rb_cArchiveEntry))
|
1047
|
+
entry = wrap<archive_entry*>(result);
|
1048
|
+
else
|
1049
|
+
entry = wrap<archive_entry*>(temp);
|
1050
|
+
}
|
1051
|
+
for(unsigned int i = 0;i < obj->entries->size();)
|
1052
|
+
{
|
1053
|
+
if(std::string(archive_entry_pathname(obj->entries->at(i))).compare(archive_entry_pathname(entry)) != 0){
|
1054
|
+
obj->entries->erase(obj->entries->begin()+i);
|
1055
|
+
obj->allbuff->erase(obj->allbuff->begin()+i);
|
1056
|
+
}else
|
1057
|
+
i++;
|
1058
|
+
}
|
1059
|
+
std::string strbuff;
|
1060
|
+
if(fd < 0 and rb_respond_to(val,rb_intern("read"))){
|
1061
|
+
VALUE result = rb_funcall(val,rb_intern("read"),0);
|
1062
|
+
strbuff.append(rb_string_value_cstr(&result), RSTRING_LEN(result));
|
1063
|
+
}else{
|
1064
|
+
while ((bytes_read = read(fd, buff, sizeof(buff))) > 0)
|
1065
|
+
strbuff.append(buff, bytes_read);
|
1066
|
+
}
|
1067
|
+
obj->entries->push_back(entry);
|
1068
|
+
obj->allbuff->push_back(strbuff);
|
1069
|
+
if(fd >= 0 and !rb_obj_is_kind_of(val,rb_cIO))
|
1070
|
+
close(fd);
|
1071
|
+
archive_read_finish(obj->file);
|
1072
|
+
return 0;
|
1073
|
+
}
|
1074
|
+
|
1075
|
+
VALUE Archive_add_block(struct add_obj *obj )
|
1076
|
+
{
|
1077
|
+
VALUE robj = obj->obj;
|
1078
|
+
char buff[8192];
|
1079
|
+
size_t bytes_read;
|
1080
|
+
archive_read_disk_set_standard_lookup(obj->file);
|
1081
|
+
if(rb_obj_is_kind_of(robj,rb_cArray)){
|
1082
|
+
for(int i=0;i< RARRAY_LEN(robj);i++){
|
1083
|
+
VALUE temp = RARRAY_PTR(robj)[i];
|
1084
|
+
int fd = -1;
|
1085
|
+
char *sourcepath,*pathname;
|
1086
|
+
if(rb_obj_is_kind_of(temp,rb_cFile)){
|
1087
|
+
VALUE rpath = rb_funcall(temp,rb_intern("path"),0); //source path
|
1088
|
+
pathname = rb_string_value_cstr(&rpath);
|
1089
|
+
VALUE obj2 = rb_file_s_expand_path(1,&rpath);
|
1090
|
+
sourcepath = rb_string_value_cstr(&obj2);
|
1091
|
+
fd = NUM2INT(rb_funcall(temp,rb_intern("fileno"),0));
|
1092
|
+
}else{
|
1093
|
+
VALUE obj2 = rb_file_s_expand_path(1,&temp);
|
1094
|
+
sourcepath = pathname = rb_string_value_cstr(&obj2);
|
1095
|
+
fd = open(pathname, O_RDONLY);
|
1096
|
+
if (fd < 0) //TODO: add error
|
1097
|
+
return Qnil;
|
1098
|
+
}
|
1099
|
+
struct archive_entry *entry = archive_entry_new();
|
1100
|
+
archive_entry_copy_sourcepath(entry, sourcepath);
|
1101
|
+
archive_entry_copy_pathname(entry, pathname);
|
1102
|
+
archive_read_disk_entry_from_file(obj->file, entry, fd, NULL);
|
1103
|
+
if(rb_block_given_p()){
|
1104
|
+
VALUE temp = wrap(entry);
|
1105
|
+
VALUE result = rb_yield(temp);
|
1106
|
+
if(rb_obj_is_kind_of(result,rb_cArchiveEntry))
|
1107
|
+
entry = wrap<archive_entry*>(result);
|
1108
|
+
else
|
1109
|
+
entry = wrap<archive_entry*>(temp);
|
1110
|
+
}
|
1111
|
+
std::string strbuff;
|
1112
|
+
while ((bytes_read = read(fd, buff, sizeof(buff))) > 0)
|
1113
|
+
strbuff.append(buff, bytes_read);
|
1114
|
+
if(fd >= 0 and !rb_obj_is_kind_of(robj,rb_cIO))
|
1115
|
+
close(fd);
|
1116
|
+
obj->entries->push_back(entry);
|
1117
|
+
obj->allbuff->push_back(strbuff);
|
1118
|
+
}
|
1119
|
+
}else if(rb_obj_is_kind_of(robj,rb_cHash)){
|
1120
|
+
archive_read_finish(obj->file);
|
1121
|
+
rb_hash_foreach(robj,(int (*)(...))Archive_add_hash_block,(VALUE)obj);
|
1122
|
+
}else {
|
1123
|
+
if(obj->fd > 0)
|
1124
|
+
archive_read_disk_entry_from_file(obj->file, obj->entry, obj->fd, NULL);
|
1125
|
+
if(rb_block_given_p()){
|
1126
|
+
VALUE temp = wrap(obj->entry);
|
1127
|
+
VALUE result = rb_yield(temp);
|
1128
|
+
if(rb_obj_is_kind_of(result,rb_cArchiveEntry))
|
1129
|
+
obj->entry = wrap<archive_entry*>(result);
|
1130
|
+
else
|
1131
|
+
obj->entry = wrap<archive_entry*>(temp);
|
1132
|
+
}
|
1133
|
+
for(unsigned int i = 0;i < obj->entries->size();)
|
1134
|
+
{
|
1135
|
+
if(std::string(archive_entry_pathname(obj->entries->at(i))).compare(archive_entry_pathname(obj->entry)) != 0){
|
1136
|
+
obj->entries->erase(obj->entries->begin()+i);
|
1137
|
+
obj->allbuff->erase(obj->allbuff->begin()+i);
|
1138
|
+
}else
|
1139
|
+
i++;
|
1140
|
+
}
|
1141
|
+
std::string strbuff;
|
1142
|
+
if(obj->fd < 0 and rb_respond_to(robj,rb_intern("read"))){
|
1143
|
+
VALUE result = rb_funcall(robj,rb_intern("read"),0);
|
1144
|
+
strbuff.append(rb_string_value_cstr(&result), RSTRING_LEN(result));
|
1145
|
+
}else{
|
1146
|
+
while ((bytes_read = read(obj->fd, buff, sizeof(buff))) > 0)
|
1147
|
+
strbuff.append(buff, bytes_read);
|
1148
|
+
}
|
1149
|
+
obj->entries->push_back(obj->entry);
|
1150
|
+
obj->allbuff->push_back(strbuff);
|
1151
|
+
}
|
1152
|
+
return Qnil;
|
1153
|
+
}
|
1154
|
+
|
1155
|
+
VALUE Archive_add_block_ensure(struct add_obj *obj )
|
1156
|
+
{
|
1157
|
+
if(!rb_obj_is_kind_of(obj->obj,rb_cHash))
|
1158
|
+
archive_read_finish(obj->file);
|
1159
|
+
for(unsigned int i=0; i<obj->entries->size(); i++){
|
1160
|
+
archive_write_header(obj->archive,obj->entries->at(i));
|
1161
|
+
archive_write_data(obj->archive,obj->allbuff->at(i).c_str(),obj->allbuff->at(i).length());
|
1162
|
+
archive_write_finish_entry(obj->archive);
|
1163
|
+
}
|
1164
|
+
archive_write_finish(obj->archive);
|
1165
|
+
return Qnil;
|
1166
|
+
}
|
1167
|
+
|
994
1168
|
/*
|
995
1169
|
* call-seq:
|
996
|
-
* add( obj , path ) → self
|
997
|
-
*
|
1170
|
+
* add( obj [, path] ) → self
|
1171
|
+
* add( obj [, path] ) {|entry| } → self
|
1172
|
+
* add( [obj, ... ] ) → self
|
1173
|
+
* add( [obj, ... ] ) {|entry| } → self
|
1174
|
+
* add( { path => obj} ) → self
|
1175
|
+
* add( { path => obj} ) {|entry| } → self
|
1176
|
+
*
|
998
1177
|
* Adds a file to an archive.
|
999
1178
|
* ===Parameters
|
1000
1179
|
* [obj] String, IO, File or an object which responds to +read+.
|
@@ -1005,13 +1184,27 @@ VALUE Archive_compression_name(VALUE self)
|
|
1005
1184
|
* [FormatError] Raised if the archive format is not supported for writing.
|
1006
1185
|
*/
|
1007
1186
|
|
1008
|
-
VALUE Archive_add(VALUE self,VALUE obj,VALUE name)
|
1187
|
+
VALUE Archive_add(int argc, VALUE *argv, VALUE self)//(VALUE self,VALUE obj,VALUE name)
|
1009
1188
|
{
|
1189
|
+
VALUE obj,name;
|
1190
|
+
rb_scan_args(argc, argv, "11", &obj,&name);
|
1191
|
+
if(NIL_P(name)){
|
1192
|
+
if(rb_obj_is_kind_of(obj,rb_cFile))
|
1193
|
+
name = rb_funcall(name,rb_intern("path"),0);
|
1194
|
+
else if(rb_obj_is_kind_of(obj,rb_cIO))
|
1195
|
+
rb_scan_args(argc, argv, "20", &obj,&name);
|
1196
|
+
else if(rb_respond_to(obj,rb_intern("read")))
|
1197
|
+
rb_scan_args(argc, argv, "20", &obj,&name);
|
1198
|
+
else if(rb_obj_is_kind_of(obj,rb_cArray) or rb_obj_is_kind_of(obj,rb_cHash))
|
1199
|
+
rb_scan_args(argc, argv, "10", &obj);
|
1200
|
+
else
|
1201
|
+
name = obj;
|
1202
|
+
}
|
1010
1203
|
char buff[8192];
|
1011
1204
|
char *path = NULL;
|
1012
1205
|
|
1013
1206
|
size_t bytes_read;
|
1014
|
-
struct archive *a = archive_read_new(),*b=archive_write_new()
|
1207
|
+
struct archive *a = archive_read_new(),*b=archive_write_new();
|
1015
1208
|
struct archive_entry *entry;
|
1016
1209
|
std::vector<struct archive_entry *> entries;
|
1017
1210
|
std::vector<std::string> allbuff;
|
@@ -1020,8 +1213,7 @@ VALUE Archive_add(VALUE self,VALUE obj,VALUE name)
|
|
1020
1213
|
archive_read_support_format_all(a);
|
1021
1214
|
archive_read_support_format_raw(a);
|
1022
1215
|
//autodetect format and compression
|
1023
|
-
|
1024
|
-
if(error==ARCHIVE_OK){
|
1216
|
+
if(Archive_read_ruby(self,a)==ARCHIVE_OK){
|
1025
1217
|
while(archive_read_next_header(a, &entry)==ARCHIVE_OK){
|
1026
1218
|
entries.push_back(archive_entry_clone(entry));
|
1027
1219
|
allbuff.push_back(std::string(""));
|
@@ -1036,14 +1228,14 @@ VALUE Archive_add(VALUE self,VALUE obj,VALUE name)
|
|
1036
1228
|
compression = archive_compression(a);
|
1037
1229
|
archive_read_finish(a);
|
1038
1230
|
}
|
1039
|
-
if(rb_obj_is_kind_of(obj,
|
1040
|
-
fd = NUM2INT(rb_funcall(obj,rb_intern("fileno"),0));
|
1041
|
-
}else if(rb_obj_is_kind_of(obj,rb_cFile)){
|
1231
|
+
if(rb_obj_is_kind_of(obj,rb_cFile)){
|
1042
1232
|
VALUE pathname = rb_funcall(obj,rb_intern("path"),0); //source path
|
1043
1233
|
VALUE obj2 = rb_file_s_expand_path(1,&pathname);
|
1044
1234
|
path = rb_string_value_cstr(&obj2);
|
1045
1235
|
fd = NUM2INT(rb_funcall(obj,rb_intern("fileno"),0));
|
1046
|
-
}else if(
|
1236
|
+
}else if(rb_obj_is_kind_of(obj,rb_cIO)){
|
1237
|
+
fd = NUM2INT(rb_funcall(obj,rb_intern("fileno"),0));
|
1238
|
+
}else if(rb_respond_to(obj,rb_intern("read")) or rb_obj_is_kind_of(obj,rb_cArray) or rb_obj_is_kind_of(obj,rb_cHash)){
|
1047
1239
|
//stringio has neigther path or fileno, so do nothing
|
1048
1240
|
}else {
|
1049
1241
|
VALUE obj2 = rb_file_s_expand_path(1,&obj);
|
@@ -1057,34 +1249,21 @@ VALUE Archive_add(VALUE self,VALUE obj,VALUE name)
|
|
1057
1249
|
rb_raise(rb_eArchiveErrorFormat,"error:%d:%s",archive_errno(b),archive_error_string(b));
|
1058
1250
|
Archive_write_set_compression(b,compression);
|
1059
1251
|
|
1060
|
-
|
1061
|
-
if(error==ARCHIVE_OK){
|
1062
|
-
for(unsigned int i=0; i<entries.size(); i++){
|
1063
|
-
if(std::string(rb_string_value_cstr(&name)).compare(archive_entry_pathname(entries[i]))!=0){
|
1064
|
-
archive_write_header(b,entries[i]);
|
1065
|
-
archive_write_data(b,allbuff[i].c_str(),allbuff[i].length());
|
1066
|
-
archive_write_finish_entry(b);
|
1067
|
-
}
|
1068
|
-
}
|
1069
|
-
archive_read_disk_set_standard_lookup(c);
|
1252
|
+
if(Archive_write_ruby(self,b)==ARCHIVE_OK){
|
1070
1253
|
entry = archive_entry_new();
|
1071
1254
|
if (path)
|
1072
1255
|
archive_entry_copy_sourcepath(entry, path);
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
}
|
1085
|
-
archive_write_finish_entry(b);
|
1086
|
-
archive_read_finish(c);
|
1087
|
-
archive_write_finish(b);
|
1256
|
+
if(!NIL_P(name))
|
1257
|
+
archive_entry_copy_pathname(entry, rb_string_value_cstr(&name));
|
1258
|
+
add_obj temp;
|
1259
|
+
temp.archive = b;
|
1260
|
+
temp.file = archive_read_disk_new();
|
1261
|
+
temp.entry = entry;
|
1262
|
+
temp.fd = fd;
|
1263
|
+
temp.obj = obj;
|
1264
|
+
temp.entries = &entries;
|
1265
|
+
temp.allbuff = &allbuff;
|
1266
|
+
RB_ENSURE(Archive_add_block,&temp,Archive_add_block_ensure,&temp);
|
1088
1267
|
}
|
1089
1268
|
|
1090
1269
|
if(fd >= 0 and !rb_obj_is_kind_of(name,rb_cIO))
|
@@ -1107,10 +1286,7 @@ VALUE Archive_add(VALUE self,VALUE obj,VALUE name)
|
|
1107
1286
|
*/
|
1108
1287
|
VALUE Archive_add_shift(VALUE self,VALUE name)
|
1109
1288
|
{
|
1110
|
-
|
1111
|
-
return Archive_add(self,name,rb_funcall(name,rb_intern("path"),0));
|
1112
|
-
else
|
1113
|
-
return Archive_add(self,name,name);
|
1289
|
+
return Archive_add(1,&name,self);
|
1114
1290
|
}
|
1115
1291
|
|
1116
1292
|
/*
|
@@ -1511,7 +1687,7 @@ extern "C" void Init_archive(void){
|
|
1511
1687
|
|
1512
1688
|
//rb_define_method(rb_cArchive,"move_to",RUBY_METHOD_FUNC(Archive_move_to),1);
|
1513
1689
|
|
1514
|
-
rb_define_method(rb_cArchive,"add",RUBY_METHOD_FUNC(Archive_add)
|
1690
|
+
rb_define_method(rb_cArchive,"add",RUBY_METHOD_FUNC(Archive_add),-1);
|
1515
1691
|
rb_define_method(rb_cArchive,"<<",RUBY_METHOD_FUNC(Archive_add_shift),1);
|
1516
1692
|
|
1517
1693
|
rb_define_method(rb_cArchive,"inspect",RUBY_METHOD_FUNC(Archive_inspect),0);
|
data/ext/entry.cpp
CHANGED
@@ -472,37 +472,66 @@ VALUE ArchiveEntry_inspect(VALUE self){
|
|
472
472
|
|
473
473
|
//ACL added later with acl gem
|
474
474
|
|
475
|
-
VALUE
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
475
|
+
VALUE ArchiveEntry_access_acl(VALUE self){
|
476
|
+
if(rb_const_defined(rb_cObject,rb_intern("ACL"))){
|
477
|
+
VALUE rb_cAcl = rb_const_get(rb_cObject,rb_intern("ACL"));
|
478
|
+
VALUE rb_cAclEntry = rb_const_get(rb_cObject,rb_intern("Entry"));
|
479
|
+
VALUE result = rb_class_new_instance(0,NULL,rb_cAcl);
|
480
|
+
archive_entry_acl_reset(_self,ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
|
481
|
+
int type,permset,tag,qual;
|
482
|
+
const char* name;
|
483
|
+
while(archive_entry_acl_next(_self, ARCHIVE_ENTRY_ACL_TYPE_ACCESS,&type, &permset, &tag,&qual, &name) == 0){
|
484
|
+
VALUE entry;
|
485
|
+
VALUE temp[3];
|
486
|
+
switch(tag){
|
487
|
+
case ARCHIVE_ENTRY_ACL_USER:
|
488
|
+
case ARCHIVE_ENTRY_ACL_USER_OBJ:
|
489
|
+
temp[0] = ID2SYM(rb_intern("user"));
|
490
|
+
break;
|
491
|
+
case ARCHIVE_ENTRY_ACL_GROUP:
|
492
|
+
case ARCHIVE_ENTRY_ACL_GROUP_OBJ:
|
493
|
+
temp[0] = ID2SYM(rb_intern("group"));
|
494
|
+
break;
|
495
|
+
case ARCHIVE_ENTRY_ACL_MASK:
|
496
|
+
temp[0] = ID2SYM(rb_intern("mask"));
|
497
|
+
break;
|
498
|
+
case ARCHIVE_ENTRY_ACL_OTHER:
|
499
|
+
temp[0] = ID2SYM(rb_intern("other"));
|
500
|
+
break;
|
501
|
+
}
|
502
|
+
temp[1] = INT2NUM(permset);
|
503
|
+
switch(tag){
|
504
|
+
case ARCHIVE_ENTRY_ACL_USER:
|
505
|
+
case ARCHIVE_ENTRY_ACL_GROUP:
|
506
|
+
temp[2] = INT2NUM(qual);
|
507
|
+
entry=rb_class_new_instance(3,temp,rb_cAclEntry);
|
508
|
+
break;
|
509
|
+
default:
|
510
|
+
entry=rb_class_new_instance(2,temp,rb_cAclEntry);
|
511
|
+
break;
|
512
|
+
}
|
513
|
+
rb_funcall(result,rb_intern("<<"),1,entry);
|
514
|
+
}
|
515
|
+
return result;
|
516
|
+
}else
|
517
|
+
rb_raise(rb_eNotImpError,"this function require the libacl-ruby gem!");
|
482
518
|
return Qnil;
|
483
519
|
}
|
484
520
|
|
485
|
-
VALUE ArchiveEntry_access_acl_count(VALUE self){
|
486
|
-
return INT2NUM(archive_entry_acl_count(_self,ARCHIVE_ENTRY_ACL_TYPE_ACCESS));
|
487
|
-
}
|
488
|
-
|
489
521
|
VALUE ArchiveEntry_acl_add(VALUE self){
|
490
522
|
archive_entry_acl_add_entry(_self,ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, ARCHIVE_ENTRY_ACL_GROUP,
|
491
523
|
101, "abc");
|
492
524
|
return self;
|
493
525
|
}
|
494
526
|
|
495
|
-
|
527
|
+
|
496
528
|
VALUE ArchiveEntry_initialize_copy(VALUE self,VALUE source)
|
497
529
|
{
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
return result;
|
530
|
+
rarchive_entry *file;
|
531
|
+
Data_Get_Struct( self, rarchive_entry, file);
|
532
|
+
file->entry = archive_entry_clone(wrap<archive_entry*>(source));
|
533
|
+
return self;
|
504
534
|
}
|
505
|
-
*/
|
506
535
|
|
507
536
|
|
508
537
|
/* Document-attr: atime
|
@@ -531,7 +560,7 @@ void Init_archive_entry(VALUE rb_cArchive){
|
|
531
560
|
#endif
|
532
561
|
rb_cArchiveEntry = rb_define_class_under(rb_cArchive,"Entry",rb_cObject);
|
533
562
|
rb_define_alloc_func(rb_cArchiveEntry,ArchiveEntry_alloc);
|
534
|
-
|
563
|
+
rb_define_private_method(rb_cArchiveEntry,"initialize_copy",RUBY_METHOD_FUNC(ArchiveEntry_initialize_copy),1);
|
535
564
|
rb_define_method(rb_cArchiveEntry,"inspect",RUBY_METHOD_FUNC(ArchiveEntry_inspect),0);
|
536
565
|
|
537
566
|
rb_define_method(rb_cArchiveEntry,"gname",RUBY_METHOD_FUNC(ArchiveEntry_gname),0);
|
@@ -581,11 +610,8 @@ void Init_archive_entry(VALUE rb_cArchive){
|
|
581
610
|
rb_define_method(rb_cArchiveEntry,"<=>",RUBY_METHOD_FUNC(ArchiveEntry_compare),1);
|
582
611
|
|
583
612
|
rb_define_alias(rb_cArchiveEntry,"to_s","path");
|
584
|
-
|
585
|
-
|
586
|
-
//rb_define_method(rb_cArchiveEntry,"acl_add",RUBY_METHOD_FUNC(ArchiveEntry_acl_add),0);
|
587
|
-
|
588
|
-
//rb_define_method(rb_cArchiveEntry,"access_acl_count",RUBY_METHOD_FUNC(ArchiveEntry_access_acl_count),0);
|
613
|
+
//*
|
614
|
+
rb_define_method(rb_cArchiveEntry,"access_acl",RUBY_METHOD_FUNC(ArchiveEntry_access_acl),0);
|
589
615
|
//*/
|
590
616
|
|
591
617
|
|
data/ext/main.hpp
CHANGED
@@ -28,6 +28,7 @@ with libarchive-ruby; if not, write to the Free Software Foundation, Inc.,
|
|
28
28
|
#include <fcntl.h>
|
29
29
|
#include <string>
|
30
30
|
extern VALUE rb_cArchive,rb_cArchiveEntry;
|
31
|
+
|
31
32
|
void Init_archive_entry(VALUE m);
|
32
33
|
|
33
34
|
template <typename T>
|
@@ -50,6 +51,10 @@ struct rarchive{
|
|
50
51
|
int compression;
|
51
52
|
};
|
52
53
|
|
54
|
+
struct rarchive_entry{
|
55
|
+
archive_entry *entry;
|
56
|
+
};
|
57
|
+
|
53
58
|
template <>
|
54
59
|
inline VALUE wrap< rarchive >(rarchive *file )
|
55
60
|
{
|
@@ -69,7 +74,10 @@ inline rarchive* wrap< rarchive* >(const VALUE &vfile)
|
|
69
74
|
template <>
|
70
75
|
inline VALUE wrap< archive_entry >(struct archive_entry *entry )
|
71
76
|
{
|
72
|
-
|
77
|
+
rarchive_entry *temp = new rarchive_entry;
|
78
|
+
//archive_entry other = archive_entry_clone(entry);
|
79
|
+
temp->entry = archive_entry_clone(entry);
|
80
|
+
return Data_Wrap_Struct(rb_cArchiveEntry, NULL, free, temp);
|
73
81
|
}
|
74
82
|
|
75
83
|
template <>
|
@@ -77,9 +85,9 @@ inline archive_entry* wrap< archive_entry* >(const VALUE &vfile)
|
|
77
85
|
{
|
78
86
|
if ( ! rb_obj_is_kind_of(vfile, rb_cArchiveEntry) )
|
79
87
|
return NULL;
|
80
|
-
|
81
|
-
Data_Get_Struct( vfile,
|
82
|
-
return file;
|
88
|
+
rarchive_entry *file;
|
89
|
+
Data_Get_Struct( vfile, rarchive_entry, file);
|
90
|
+
return file->entry;
|
83
91
|
}
|
84
92
|
|
85
93
|
#endif /* __RubyAchiveMain_H__ */
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libarchive-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.0.1.dev
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Hanmac
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2011-
|
17
|
+
date: 2011-05-13 00:00:00 +02:00
|
19
18
|
default_executable:
|
20
19
|
dependencies: []
|
21
20
|
|
@@ -61,13 +60,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
61
|
none: false
|
63
62
|
requirements:
|
64
|
-
- - "
|
63
|
+
- - ">="
|
65
64
|
- !ruby/object:Gem::Version
|
66
65
|
segments:
|
67
|
-
-
|
68
|
-
|
69
|
-
- 1
|
70
|
-
version: 1.3.1
|
66
|
+
- 0
|
67
|
+
version: "0"
|
71
68
|
requirements:
|
72
69
|
- A C++ compiler
|
73
70
|
- libarchive library
|