Skip to content

Commit

Permalink
#3: Do not attempt to get file system lock on non-existent files.
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonQ committed Aug 10, 2017
1 parent f76836d commit 227d619
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions FileParser.vb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ Class FileParser
SyncSettings = {NewSyncSettings}
End If

SourceFileStream = WaitForFile(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read, FileTimeout)
If SourceFileStream Is Nothing Then
MyLog.Write(ProcessID, "Could not get file system lock on source file: """ & FilePath.Substring(MyGlobalSyncSettings.SourceDirectory.Length) & """.", Warning)
FileLock = False
If File.Exists(FilePath) Then
SourceFileStream = WaitForFile(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read, FileTimeout)
If SourceFileStream Is Nothing Then
MyLog.Write(ProcessID, "Could not get file system lock on source file: """ & FilePath.Substring(MyGlobalSyncSettings.SourceDirectory.Length) & """.", Warning)
FileLock = False
Else
FileLock = True
End If
Else
FileLock = True
MyLog.Write(ProcessID, "Source file doesn't exist: """ & FilePath.Substring(MyGlobalSyncSettings.SourceDirectory.Length) & """.", Warning)
FileLock = False
End If

End Sub
Expand Down Expand Up @@ -103,6 +108,7 @@ Class FileParser
Dim MyReturnObject As ReturnObject

Try
If Not FileLock Then Throw New System.Exception("Could not get file system lock on source file.")
Dim NewFilesSize As Int64 = 0
For Each SyncSetting In SyncSettings
Dim FileCodec As Codec = CheckFileCodec(SyncSetting.GetWatcherCodecs())
Expand Down Expand Up @@ -188,6 +194,7 @@ Class FileParser
Dim MyReturnObject As ReturnObject

Try
If Not FileLock Then Throw New System.Exception("Could not get file system lock on source file.")
For Each SyncSetting In SyncSettings
Dim FileCodec As Codec = CheckFileCodec(SyncSetting.GetWatcherCodecs())
If Not FileCodec Is Nothing Then
Expand Down Expand Up @@ -291,7 +298,7 @@ Class FileParser
#End Region

#Region " File Checks "
Public Function CheckFileForSync(ByVal FileCodec As Codec, SyncSetting As SyncSettings) As Boolean
Private Function CheckFileForSync(ByVal FileCodec As Codec, SyncSetting As SyncSettings) As Boolean

Try
If CheckFileTags(FileCodec, SyncSetting) Then
Expand All @@ -308,7 +315,7 @@ Class FileParser

End Function

Public Function CheckFileCodec(CodecsToCheck As Codec()) As Codec
Private Function CheckFileCodec(CodecsToCheck As Codec()) As Codec

Dim FileExtension As String = Path.GetExtension(FilePath)

Expand All @@ -328,11 +335,6 @@ Class FileParser

Private Function CheckFileTags(MyCodec As Codec, SyncSetting As SyncSettings) As Boolean

If FileLock = False Then
MyLog.Write(ProcessID, "...could not obtain file tags. Could not get file system lock on source file.", Warning)
Return False
End If

Dim TagsObject As ReturnObject = MyCodec.MatchTag(FilePath, SyncSetting.GetWatcherTags)

If TagsObject.Success Then
Expand Down

0 comments on commit 227d619

Please sign in to comment.