Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

ZipFile CreateFromDirectory creating corrupted archive?

$
0
0

Hello,

Our service is processing huge amount of data and needs to do quite verbose logging - so we produce few dozens GB of log data per day. After day end we archive our previous day logs by using this function:

private static void ArchiveDirectory(string target_dir)
{
	try
	{
		if (Directory.Exists(target_dir) && !File.Exists(target_dir + ".zip"))
		{
			System.IO.Compression.ZipFile.CreateFromDirectory(target_dir, target_dir + ".zip");
			DeleteDirectory(target_dir);
		}
	}
	catch (Exception)
	{ /* This is intentional as there is no place to log during log archival */ } 
}      
       

 It happened few times that the log files were archived into an archive, original folder was deleted, but the archive was corrupted (some files couldn't be opened (Windows giving 0x80004005 - Unspecified Error) and archive couldn't be completely unpacked, archive validation tools (e.g. winrar) reported corruption).

Is it possible that ZipFile.CreateFromDirectory can create corrupted archives without throwing an exception? How can one programaticaly validate the archive before proceeding with deletion?

Thanks
Jan


Viewing all articles
Browse latest Browse all 8156


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>