Permalink
Browse files

Fixed bug where file modification time can get set incorrectly

This fixes an issue discussed on the forums here:
https://forums.sagetv.com/forums/showthread.php?t=65445
where asynchronous closing of files on Windows can cause SageTV
to incorrectly modify the timestamp when appending the metadata
to a back-to-back recording.
  • Loading branch information...
Narflex committed Apr 17, 2018
1 parent 4045d6f commit 85684c5b944cbfe5365031ab28553805fec747d1
Showing with 9 additions and 3 deletions.
  1. +9 −3 java/sage/media/format/MpegMetadata.java
@@ -293,7 +293,7 @@ else if (MediaFormat.MPEG2_PS.equals(format.getFormatName()))
}
try
{
addFileMetadata(mf.getFile(0), type, rv.toString());
addFileMetadata(mf.getFile(0), type, rv.toString(), mf.getRecordEnd());
}
catch (java.io.IOException e)
{
@@ -392,12 +392,18 @@ else if (c == '=')
// 1: Mpeg2-TS
// 2: Mpeg2-TS with 4 bytes extra header (.m2ts)
public static void addFileMetadata(java.io.File f, int type, String metadataStr) throws java.io.IOException
public static void addFileMetadata(java.io.File f, int type, String metadataStr, long targetFileTime) throws java.io.IOException
{
int i, j, packetcount=0;
int pos=0;
// PRESERVE TIMESTAMP ON THE FILE!!!
long fileTime = f.lastModified();
if (targetFileTime != 0 && Math.abs(targetFileTime - fileTime) > 30000) {
// There's an issue on Windows where the file closing is done asynchronously sometimes and may not have occurred by the time
// we get here so the file modification time may not have been updated yet. So ensure we don't go setting the modification time
// to the creation time if we received a suggestion that is more than 30 seconds off from the modification time.
fileTime = targetFileTime;
}
sage.io.SageDataFile ra = new sage.io.SageDataFile(new sage.io.BufferedSageFile(new sage.io.LocalSageFile(f, false)), sage.Sage.BYTE_CHARSET);
try
{
@@ -704,7 +710,7 @@ public static void main(String[] args)
}
try
{
addFileMetadata(f, new Integer(args[2]).intValue(), args[3]);
addFileMetadata(f, new Integer(args[2]).intValue(), args[3], 0);
}
catch(Exception e)
{

0 comments on commit 85684c5

Please sign in to comment.