1

Closed

FileNotFoundException when creating a Self Extracting Zip file

description

When creating self extracting zips with multiple threads this error occurs:
 
Message: Could not find file 'E:\TEMP\Ionic.Zip-2011May06-141232-1.exe'.
Source: mscorlib
TargetSite:
 
ErrorType: System.IO.FileNotFoundException
 
It looks like the there are no locks around the critical section where the file name is being generated or its existence is begin checked. Another solution would be to use a GUID as the file name.
 
internal static string GenerateTempPathname(string extension)
    {
        string candidate = null;
        String AppName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
        string parentDir = System.IO.Path.GetTempPath();
        int index = 0;
        do
        {
            index++;
            string Name = String.Format("{0}-{1}-{2}.{3}",
                    AppName, System.DateTime.Now.ToString("yyyyMMMdd-HHmmss"), index, extension);
            candidate = System.IO.Path.Combine(parentDir, Name);
        } while (System.IO.File.Exists(candidate) || System.IO.Directory.Exists(candidate));
 
        // this file/path does not exist.  It can now be created, as file or directory.
        return candidate;
    }
Closed Jun 22, 2011 at 12:37 AM by Cheeso
fixed in changeset 79579. The first binary with this fix will be v1.9.1.6

comments