fix(core): initial compat work on libzip
parent
f246d88a5c
commit
3c4b1af3ba
|
@ -25,7 +25,8 @@
|
||||||
|
|
||||||
@interface SOGoZipArchiver : NSObject
|
@interface SOGoZipArchiver : NSObject
|
||||||
{
|
{
|
||||||
zip_t *zip;
|
/* we use zip instead of zip_t for backward compatibility */
|
||||||
|
struct zip *z;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initFromFile: (NSString *) file;
|
- (id) initFromFile: (NSString *) file;
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
- (id)init
|
- (id)init
|
||||||
{
|
{
|
||||||
if ((self = [super init])) {
|
if ((self = [super init])) {
|
||||||
zip = NULL;
|
z = NULL;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -54,8 +54,8 @@
|
||||||
if (file) {
|
if (file) {
|
||||||
if ((self = [self init])) {
|
if ((self = [self init])) {
|
||||||
int errorp;
|
int errorp;
|
||||||
self->zip = zip_open([file cString], ZIP_CREATE | ZIP_EXCL, &errorp);
|
self->z = zip_open([file cString], ZIP_CREATE | ZIP_EXCL, &errorp);
|
||||||
if (self->zip == NULL) {
|
if (self->z == NULL) {
|
||||||
zip_error_t ziperror;
|
zip_error_t ziperror;
|
||||||
zip_error_init_with_code(&ziperror, errorp);
|
zip_error_init_with_code(&ziperror, errorp);
|
||||||
NSLog(@"Failed to open zip output file %@: %@", file,
|
NSLog(@"Failed to open zip output file %@: %@", file,
|
||||||
|
@ -71,19 +71,19 @@
|
||||||
|
|
||||||
- (BOOL)putFileWithName:(NSString *)filename andData:(NSData *)data
|
- (BOOL)putFileWithName:(NSString *)filename andData:(NSData *)data
|
||||||
{
|
{
|
||||||
if (self->zip == NULL) {
|
if (self->z == NULL) {
|
||||||
NSLog(@"Failed to add file, archive is not open");
|
NSLog(@"Failed to add file, archive is not open");
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
zip_source_t *source = zip_source_buffer(self->zip, [data bytes], [data length], 0);
|
zip_source_t *source = zip_source_buffer(self->z, [data bytes], [data length], 0);
|
||||||
if (source == NULL) {
|
if (source == NULL) {
|
||||||
NSLog(@"Failed to create zip source from buffer: %@", [NSString stringWithCString: zip_strerror(self->zip)]);
|
NSLog(@"Failed to create zip source from buffer: %@", [NSString stringWithCString: zip_strerror(self->z)]);
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zip_file_add(self->zip, [filename UTF8String], source, ZIP_FL_ENC_UTF_8) < 0) {
|
if (zip_file_add(self->z, [filename UTF8String], source, ZIP_FL_ENC_UTF_8) < 0) {
|
||||||
NSLog(@"Failed to add file %@: %@", filename, [NSString stringWithCString: zip_strerror(self->zip)]);
|
NSLog(@"Failed to add file %@: %@", filename, [NSString stringWithCString: zip_strerror(self->z)]);
|
||||||
zip_source_free(source);
|
zip_source_free(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,13 +93,13 @@
|
||||||
- (BOOL)close
|
- (BOOL)close
|
||||||
{
|
{
|
||||||
BOOL success = YES;
|
BOOL success = YES;
|
||||||
if (self->zip != NULL) {
|
if (self->z != NULL) {
|
||||||
if (zip_close(zip) != 0) {
|
if (zip_close(self->z) != 0) {
|
||||||
NSLog(@"Failed to close zip archive: %@", [NSString stringWithCString: zip_strerror(self->zip)]);
|
NSLog(@"Failed to close zip archive: %@", [NSString stringWithCString: zip_strerror(self->z)]);
|
||||||
zip_discard(self->zip);
|
zip_discard(self->z);
|
||||||
success = NO;
|
success = NO;
|
||||||
}
|
}
|
||||||
self->zip = NULL;
|
self->z = NULL;
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue