@ -284,32 +284,36 @@ public class DirectoryArchiver {
encryptedFileSize
)
// I f t h e f i l e i s a h i d d e n f i l e ( s h o u l d n ' t b e p o s s i b l e a n y m o r e b u t o l d b a c k u p s h a d t h i s
// i s s u e ) t h e n j u s t s k i p t h e f i l e - a n y h i d d e n f i l e s a r e f r o m A p p l e a n d s e e m t o f a i l t o
// d e c r y p t c a u s i n g t h e e n t i r e i m p o r t t o f a i l
guard ! URL ( fileURLWithPath : relativePath ) . lastPathComponent . starts ( with : " . " ) else {
Log . warn ( . cat , " Skipping hidden file to avoid breaking the import: \( relativePath ) " )
skippedFilePaths . append ( fullPath )
// U p d a t e t h e p r o g r e s s
fileAmountProcessed += fileSize
progressChanged ? (
( filePaths . count + skippedFilePaths . count + additionalFilePaths . count ) ,
Int ( expectedFileCount + expectedAdditionalFileCount ) ,
fileAmountProcessed ,
encryptedFileSize
)
continue
}
// R e a d a n d d e c r y p t f i l e c o n t e n t
guard let outputStream : OutputStream = OutputStream ( toFileAtPath : fullPath , append : false ) else {
Log . error ( . cat , " Failed to create output stream " )
throw ArchiveError . unarchiveFailed
let outputStream : OutputStream ?
let isHiddenFile : Bool = URL ( fileURLWithPath : relativePath ) . lastPathComponent . starts ( with : " . " )
defer { outputStream ? . close ( ) }
switch isHiddenFile {
case true :
// I f t h e f i l e i s a h i d d e n f i l e ( s h o u l d n ' t b e p o s s i b l e a n y m o r e b u t o l d b a c k u p s h a d t h i s
// i s s u e ) t h e n j u s t s k i p t h e f i l e - a n y h i d d e n f i l e s a r e f r o m A p p l e a n d s e e m t o f a i l t o
// d e c r y p t c a u s i n g t h e e n t i r e i m p o r t t o f a i l
//
// N o t e : W e s t i l l n e e d t o p r o c e s s t h e f i l e i n o r d e r t o e n s u r e t h e i n p u t S t r e a m i s m o v e d
// t h e c o r r e c t a m o u n t , o t h e r w i s e o u t b y t e a l i g n m e n t c o u l d b e o f f w h i c h w i l l r e s u l t i n
// a t b e s t a f a i l e d i m p o r t , b u t m o r e l i k e l y a c r a s h d u e t o i n v a l i d s i z e d a t a
Log . warn ( . cat , " Skipping hidden file to avoid breaking the import: \( relativePath ) " )
skippedFilePaths . append ( fullPath )
outputStream = nil
case false :
// I t ' s a v a l i d f i l e s o e n s u r e t h e O u t p u t S t r e a m w a s o p e n e d s u c c e s s f u l l y
outputStream = OutputStream ( toFileAtPath : fullPath , append : false )
outputStream ? . open ( )
guard outputStream != nil else {
Log . error ( . cat , " Failed to create output stream " )
throw ArchiveError . unarchiveFailed
}
}
outputStream . open ( )
defer { outputStream . close ( ) }
// P r o c e s s t h e f i l e c h u n k b y c h u n k
var remainingFileSize : Int = Int ( fileSize )
while remainingFileSize > 0 {
let ( chunk , chunkSizeBytesRead , encryptedSize ) : ( [ UInt8 ] , Int , UInt32 ) = try read (
@ -318,7 +322,7 @@ public class DirectoryArchiver {
)
// W r i t e t o t h e o u t p u t
outputStream .write ( chunk , maxLength : chunk . count )
outputStream ? .write ( chunk , maxLength : chunk . count )
remainingFileSize -= chunk . count
// U p d a t e t h e p r o g r e s s
@ -332,9 +336,10 @@ public class DirectoryArchiver {
}
// S t o r e t h e f i l e p a t h i n f o a n d u p d a t e t h e p r o g r e s s
switch isExtraFile {
case false : filePaths . append ( fullPath )
case true : additionalFilePaths . append ( fullPath )
switch ( isExtraFile , isHiddenFile ) {
case ( _ , true ) : break
case ( false , false ) : filePaths . append ( fullPath )
case ( true , false ) : additionalFilePaths . append ( fullPath )
}
progressChanged ? (
( filePaths . count + skippedFilePaths . count + additionalFilePaths . count ) ,