Permalink
Browse files

Fix for systems without file locking

  • Loading branch information...
xmodx10 committed Jul 27, 2018
1 parent e3cd600 commit b93bde25e7dbb2fca99d5ca8b1f2585bc75a0707
Showing with 28 additions and 0 deletions.
  1. +28 −0 Shoko.Server/Commands/Import/CommandRequest_HashFile.cs
@@ -88,6 +88,27 @@ private long CanAccessFile(string fileName)
}
}

//Used to check if file has been modified within the last X seconds.
private bool FileModified(string FileName, int Seconds)
{
try
{
if (System.IO.File.GetLastWriteTime(FileName).AddSeconds(Seconds) >= DateTime.Now)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
logger.Error(ex);
return false;
}
}

private void ProcessFile_LocalInfo()
{
// hash and read media info for file
@@ -133,6 +154,13 @@ private void ProcessFile_LocalInfo()
logger.Error("Could not access file: " + FileName);
return;
}

//For systems with no locking
while (FileModified(FileName, 3))
{
Thread.Sleep(1000);
logger.Error($@"An external process is modifying the file, {FileName}");
}
}


0 comments on commit b93bde2

Please sign in to comment.