Permalink
Browse files

Updating unzip with wrong password to stop at first file failure; cal…

…ling error callback once; and also return success = NO.

Also adding a test target with some tests to verify behaviour.

See Issue #10
  • Loading branch information...
1 parent 89e2137 commit 47a037776d9d953a7141dd519cd31ee496d569aa @mattconnolly committed Nov 8, 2012
View
@@ -39,7 +39,7 @@ -(id) init
{
if( self=[super init] )
{
- _zipFile = NULL ;
+ _zipFile = NULL;
}
return self;
}
@@ -311,9 +311,6 @@ -(BOOL) UnzipFileTo:(NSString*) path overWrite:(BOOL) overwrite
{
// don't process any more of the file, but continue
break;
-// unzCloseCurrentFile( _unzFile );
-// ret = unzGoToNextFile( _unzFile );
-// continue;
}
}
fp = fopen( (const char*)[fullPath UTF8String], "wb");
@@ -326,6 +323,8 @@ -(BOOL) UnzipFileTo:(NSString*) path overWrite:(BOOL) overwrite
}
else // if (read < 0)
{
+ ret = read; // result will be an error code
+ success = NO;
[self OutputErrorMessage:@"Failed to reading zip file"];
}
} while (read > 0);
@@ -360,15 +359,26 @@ -(BOOL) UnzipFileTo:(NSString*) path overWrite:(BOOL) overwrite
}
}
- unzCloseCurrentFile( _unzFile );
- ret = unzGoToNextFile( _unzFile );
+
+ if (ret == UNZ_OK) {
+ ret = unzCloseCurrentFile( _unzFile );
+ if (ret != UNZ_OK) {
+ [self OutputErrorMessage:@"file was unzipped but failed crc check"];
+ success = NO;
+ }
+ }
+
+ if (ret == UNZ_OK) {
+ ret = unzGoToNextFile( _unzFile );
+ }
+
if (_progressBlock && _numFiles) {
index++;
int p = index*100/_numFiles;
progress = p;
_progressBlock(progress, index, _numFiles);
}
- }while( ret==UNZ_OK && UNZ_OK!=UNZ_END_OF_LIST_OF_FILE );
+ } while (ret==UNZ_OK && UNZ_OK!=UNZ_END_OF_LIST_OF_FILE);
return success;
}
Oops, something went wrong.

0 comments on commit 47a0377

Please sign in to comment.