aegif / CmisSync

Synchronize content between a CMIS repository and your desktop. Like Dropbox for Enterprise Content Management!
http://CmisSync.com
164 stars 123 forks source link

Crash sometimes when config.xml opened by another program #316

Open nicolas-raoul opened 10 years ago

nicolas-raoul commented 10 years ago

When reading config.xml with another program, CmisSync crashes:

System.IO.IOException was unhandled
  HResult=-2147024864
  Message=The process cannot access the file 'C:\Users\win7pro32bit\AppData\Roaming\cmissync\config.xml' because it is being used by another process.
  Source=mscorlib
  StackTrace:
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
       at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
       at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost)
       at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
       at System.IO.StreamWriter..ctor(String path)
       at CmisSync.Lib.Config.Save()
       at CmisSync.Lib.RepoBase.OnSyncComplete(Boolean syncFull)
       at CmisSync.Lib.Sync.CmisRepo.SynchronizedFolder.SyncComplete(Boolean syncFull)
       at CmisSync.Lib.Sync.CmisRepo.SynchronizedFolder.<>c__DisplayClassa.<SyncInBackground>b__7(Object o, RunWorkerCompletedEventArgs args)
       at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
       at System.ComponentModel.BackgroundWorker.AsyncOperationCompleted(Object arg)
       at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
       at System.Threading.ThreadPoolWorkQueue.Dispatch()
       at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
  InnerException: 

Why save at every OnSyncComplete?

ymolinet commented 10 years ago

To save the last sync datetime.

nicolas-raoul commented 10 years ago

Oh, I see! Thanks for the tip :-) That sounds reasonable.

Unfortunately CmisSync crashes if config.xml is being opened by another program.

Maybe we should catch the exception, and in case of exception not save the last sync datetime (it is not vital). What do you think?

ymolinet commented 10 years ago

I don't have this issue with Notepad++. Yes, we could catch this exception but we must also ensure that the config.xml is saved on exit.

nicolas-raoul commented 10 years ago

Yes, it is very rare, just happened to me one time.

Maybe a race condition? Like if both read exactly at the same time or something? I don't know.

nicolas-raoul commented 10 years ago

Last sync datetime should be written to the SQLite database, not to the XML config file. Cheers!