mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 17:56:51 +13:00
Additional tests to make sure watch folder uploads file which is not actively written
This commit is contained in:
parent
50495242c4
commit
7fc5c51596
2 changed files with 37 additions and 2 deletions
|
@ -828,6 +828,19 @@ public static bool IsFileLocked(string path)
|
|||
return false;
|
||||
}
|
||||
|
||||
public static long GetFileSize(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new FileInfo(path).Length;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void CreateDirectoryFromDirectoryPath(string path)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(path) && !Directory.Exists(path))
|
||||
|
|
|
@ -86,8 +86,30 @@ private void fileWatcher_Created(object sender, FileSystemEventArgs e)
|
|||
|
||||
timers.Add(new WatchFolderDuplicateEventTimer(path));
|
||||
|
||||
Action onCompleted = () => context.Post(state => OnFileWatcherTrigger(path), null);
|
||||
Helpers.WaitWhileAsync(() => Helpers.IsFileLocked(path), 250, 5000, onCompleted, 1000);
|
||||
int successCount = 0;
|
||||
long previousSize = -1;
|
||||
|
||||
Helpers.WaitWhileAsync(() =>
|
||||
{
|
||||
if (!Helpers.IsFileLocked(path))
|
||||
{
|
||||
long currentSize = Helpers.GetFileSize(path);
|
||||
|
||||
if (currentSize > 0 && currentSize == previousSize)
|
||||
{
|
||||
successCount++;
|
||||
}
|
||||
|
||||
previousSize = currentSize;
|
||||
return successCount < 4;
|
||||
}
|
||||
|
||||
previousSize = -1;
|
||||
return true;
|
||||
}, 250, 5000, () =>
|
||||
{
|
||||
context.Post(state => OnFileWatcherTrigger(path), null);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
protected void CleanElapsedTimers()
|
||||
|
|
Loading…
Reference in a new issue