From 0408acc206a7c6f43ad45ffe4205a64a4c407aef Mon Sep 17 00:00:00 2001 From: Jim Norman Date: Tue, 11 Jul 2006 22:10:16 +0000 Subject: [PATCH] Bug 178796. MPFileWatcher created a race condition on deletion of files. --- CASA/micasad/init/CredMgr.cs | 16 ++++++++-------- CASA/micasad/lss/CASACrypto.cs | 21 +++++++++++---------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/CASA/micasad/init/CredMgr.cs b/CASA/micasad/init/CredMgr.cs index e4add38d..f1312ff8 100644 --- a/CASA/micasad/init/CredMgr.cs +++ b/CASA/micasad/init/CredMgr.cs @@ -37,7 +37,7 @@ namespace sscs.init public static void Install() { - System.Diagnostics.Debug.WriteLine("CASA: attempting to register lcredmgr"); + System.Diagnostics.Trace.WriteLine("CASA: attempting to register lcredmgr"); string sExePath = GetRegSvrPath(); if (sExePath != null) { @@ -51,7 +51,7 @@ namespace sscs.init public static void Uninstall() { - System.Diagnostics.Debug.WriteLine("CASA: attempting to unregister lcredmgr"); + System.Diagnostics.Trace.WriteLine("CASA: attempting to unregister lcredmgr"); string sExePath = GetRegSvrPath(); if (sExePath != null) { @@ -81,11 +81,11 @@ namespace sscs.init myProcess.StartInfo = myProcessStartInfo; myProcess.Start(); myProcess.WaitForExit(); - System.Diagnostics.Debug.WriteLine("Completed " + myProcess.ExitCode.ToString()); + System.Diagnostics.Trace.WriteLine("Completed " + myProcess.ExitCode.ToString()); } catch (Exception e) { - System.Diagnostics.Debug.WriteLine(e.ToString()); + System.Diagnostics.Trace.WriteLine(e.ToString()); } } } @@ -103,12 +103,12 @@ namespace sscs.init } else { - System.Diagnostics.Debug.WriteLine("Did not find regsvr32.exe"); + System.Diagnostics.Trace.WriteLine("Did not find regsvr32.exe"); } } else { - System.Diagnostics.Debug.WriteLine("Did not find System path"); + System.Diagnostics.Trace.WriteLine("Did not find System path"); } return null; @@ -125,12 +125,12 @@ namespace sscs.init } else { - System.Diagnostics.Debug.WriteLine("Did not find lcredmgr.dll"); + System.Diagnostics.Trace.WriteLine("Did not find lcredmgr.dll"); } } else { - System.Diagnostics.Debug.WriteLine("Did not find path to [ProgramFiles]"); + System.Diagnostics.Trace.WriteLine("Did not find path to [ProgramFiles]"); } return null; diff --git a/CASA/micasad/lss/CASACrypto.cs b/CASA/micasad/lss/CASACrypto.cs index 0fb0044a..c8427d27 100644 --- a/CASA/micasad/lss/CASACrypto.cs +++ b/CASA/micasad/lss/CASACrypto.cs @@ -432,11 +432,11 @@ namespace sscs.crypto CryptoStream csEncrypt = null; try { - if(File.Exists(fileName)) - File.Delete(fileName); + // NOTE: removed the delete call because the MPFileWatcher would replace it. + //if(File.Exists(fileName)) + // File.Delete(fileName); byte[] baKey = Generate16ByteKeyFromString(passwd, null, false); - //Get an encryptor. RijndaelManaged myRijndael = new RijndaelManaged(); ICryptoTransform encryptor; @@ -445,18 +445,18 @@ namespace sscs.crypto //Encrypt the data to a file fsEncrypt = new FileStream(fileName,FileMode.Create); - // make hidden - File.SetAttributes(fileName, FileAttributes.Hidden); - csEncrypt = new CryptoStream(fsEncrypt, encryptor, CryptoStreamMode.Write); - //Write all data to the crypto stream and flush it. - + //Write all data to the crypto stream and flush it. csEncrypt.Write(baMasterPasscode, 0, baMasterPasscode.Length); csEncrypt.FlushFinalBlock(); csEncrypt.Close(); fsEncrypt.Close(); + + // make hidden + File.SetAttributes(fileName, FileAttributes.Hidden); + } catch(Exception e) { @@ -668,8 +668,9 @@ namespace sscs.crypto try { - if (File.Exists(sFileName + ".IV")) - File.Delete(sFileName + ".IV"); + // NOTE: removed the delete call because the MPFileWatcher would replace it. + //if (File.Exists(sFileName + ".IV")) + // File.Delete(sFileName + ".IV"); // now save this FileStream fs = new FileStream(sFileName + ".IV", FileMode.Create);