From f3937b9f0c5221da0ddff365810363f1d5fee763 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Mon, 25 Sep 2023 07:08:41 +0100 Subject: [PATCH 1/2] Update Tdarr_Plugin_z80t_keep_original_date so works on windows --- .../Tdarr_Plugin_z80t_keep_original_date.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Community/Tdarr_Plugin_z80t_keep_original_date.js b/Community/Tdarr_Plugin_z80t_keep_original_date.js index 829d4bc..da2e589 100644 --- a/Community/Tdarr_Plugin_z80t_keep_original_date.js +++ b/Community/Tdarr_Plugin_z80t_keep_original_date.js @@ -40,6 +40,8 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { // eslint-disable-next-line import/no-unresolved,import/no-extraneous-dependencies const touch = require('touch'); + const os = require('os'); + const fs = require('fs'); const log = (msg) => { if (inputs.log === true) { @@ -57,7 +59,20 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { try { log('Changing date...'); - touch.sync(file._id, { mtimeMs: otherArguments.originalLibraryFile.statSync.mtimeMs, force: true }); + + if (os.platform() === 'win32') { + fs.utimes( + file._id, + new Date().getTime() / 1000, + otherArguments.originalLibraryFile.statSync.mtimeMs / 1000, + () => { + log('Error updating modified date'); + }, + ); + } else { + touch.sync(file._id, { mtimeMs: otherArguments.originalLibraryFile.statSync.mtimeMs, force: true }); + } + log('Done.'); responseData.infoLog += 'File timestamps updated or match original file\n'; return responseData; From 5158943290ea68fb6ae298f148634763ae9ba50b Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Mon, 25 Sep 2023 07:10:50 +0100 Subject: [PATCH 2/2] Handle error --- Community/Tdarr_Plugin_z80t_keep_original_date.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Community/Tdarr_Plugin_z80t_keep_original_date.js b/Community/Tdarr_Plugin_z80t_keep_original_date.js index da2e589..ebdd36a 100644 --- a/Community/Tdarr_Plugin_z80t_keep_original_date.js +++ b/Community/Tdarr_Plugin_z80t_keep_original_date.js @@ -60,17 +60,20 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { try { log('Changing date...'); + const { mtimeMs } = otherArguments.originalLibraryFile.statSync; if (os.platform() === 'win32') { fs.utimes( file._id, new Date().getTime() / 1000, - otherArguments.originalLibraryFile.statSync.mtimeMs / 1000, - () => { - log('Error updating modified date'); + mtimeMs / 1000, + (err) => { + if (err) { + log('Error updating modified date'); + } }, ); } else { - touch.sync(file._id, { mtimeMs: otherArguments.originalLibraryFile.statSync.mtimeMs, force: true }); + touch.sync(file._id, { mtimeMs, force: true }); } log('Done.');