Skip to content

Commit

Permalink
Fix for systems without file locking
Browse files Browse the repository at this point in the history
  • Loading branch information
xmodx10 committed Jul 28, 2018
1 parent e3cd600 commit b93bde2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Shoko.Server/Commands/Import/CommandRequest_HashFile.cs
Expand Up @@ -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
Expand Down Expand Up @@ -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}");
}
}


Expand Down

0 comments on commit b93bde2

Please sign in to comment.