Merge pull request #96 from arubenis/master
Prevent the upload of the same file multiple times if it's already opened
This commit is contained in:
Коммит
8ae902d869
|
@ -34,16 +34,22 @@ namespace RecurringIntegrationsScheduler.Common.Helpers
|
|||
/// </summary>
|
||||
/// <param name="filePath">File path</param>
|
||||
/// <returns>Stream</returns>
|
||||
public static Stream Read(string filePath)
|
||||
public static Stream Read(string filePath, FileShare fileShare = FileShare.ReadWrite)
|
||||
{
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
return new FileStream(filePath,
|
||||
FileMode.Open,
|
||||
FileAccess.ReadWrite,
|
||||
FileShare.ReadWrite,
|
||||
4096,
|
||||
true);
|
||||
try
|
||||
{
|
||||
return new FileStream(filePath,
|
||||
FileMode.Open,
|
||||
FileAccess.ReadWrite,
|
||||
fileShare,
|
||||
4096,
|
||||
true);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ namespace RecurringIntegrationsScheduler.Job
|
|||
}
|
||||
fileCount++;
|
||||
|
||||
var sourceStream = _retryPolicyForIo.Execute(() => FileOperationsHelper.Read(dataMessage.FullPath));
|
||||
var sourceStream = _retryPolicyForIo.Execute(() => FileOperationsHelper.Read(dataMessage.FullPath, FileShare.None));
|
||||
if (sourceStream == null) continue;//Nothing to do here
|
||||
|
||||
sourceStream.Seek(0, SeekOrigin.Begin);
|
||||
|
|
Загрузка…
Ссылка в новой задаче