Skip to content

Commit 946d0c1

Browse files
committed
Issue #117: introduce config MONITOR_SEC_DELAY_SCAN
1 parent 8027889 commit 946d0c1

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

ngPost.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ nzbPath = /tmp
5656
## for monitoring, ignore new incoming folders
5757
#MONITOR_IGNORE_DIR = true
5858

59+
## for monitoring, delay to check the size of an incoming file/folder to make sure it is fully arrived before posting it
60+
## must be between 1sec and 120sec (otherwise default: 1sec)
61+
MONITOR_SEC_DELAY_SCAN = 1
62+
5963

6064
## Default folder to open to select files from the HMI
6165
inputDir = /tmp

src/FoldersMonitorForNewFiles.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include <QDir>
2424
#include <QDateTime>
2525
#include <QThread>
26+
27+
ulong FoldersMonitorForNewFiles::sMSleep = 1000; //!< 1sec in case we move file from samba or unrar when the system is quite loaded
28+
2629
FoldersMonitorForNewFiles::FoldersMonitorForNewFiles(const QString &folderPath, QObject *parent) :
2730
QObject(parent), _monitor(), _stopListening(0x0)
2831
{

src/FoldersMonitorForNewFiles.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ class FoldersMonitorForNewFiles : public QObject
4747
{
4848
Q_OBJECT
4949

50+
friend class NgPost;
51+
5052
private:
5153
QFileSystemWatcher _monitor; //!< monitor
5254
QMap<QString, FolderScan*> _folders; //!< track files processed (their date might be > _lastCheck)
5355
AtomicBool _stopListening;
5456

55-
static const ulong sMSleep = 1000; //!< 1sec in case we move file from samba or unrar when the system is quite loaded
57+
static ulong sMSleep;
5658

5759

5860
public:

src/NgPost.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ const QMap<NgPost::Opt, QString> NgPost::sOptionNames =
109109
{Opt::MONITOR_FOLDERS, "monitor_nzb_folders"},
110110
{Opt::MONITOR_EXT, "monitor_extensions"},
111111
{Opt::MONITOR_IGNORE_DIR, "monitor_ignore_dir"},
112+
{Opt::MONITOR_SEC_DELAY_SCAN, "monitor_sec_delay_scan"},
112113

113114
{Opt::MSG_ID, "msg_id"},
114115
{Opt::META, "meta"},
@@ -279,7 +280,7 @@ NgPost::NgPost(int &argc, char *argv[]):
279280
_autoDirs(),
280281
_folderMonitor(nullptr), _monitorThread(nullptr),
281282
_delAuto(false),
282-
_monitor_nzb_folders(false), _monitorExtensions(), _monitorIgnoreDir(false),
283+
_monitor_nzb_folders(false), _monitorExtensions(), _monitorIgnoreDir(false), _monitorSecDelayScan(1),
283284
_keepRar(false), _packAuto(false), _packAutoKeywords(),
284285
_lang("en"), _translators(),
285286
_netMgr(), _urlNzbUpload(nullptr), _urlNzbUploadStr(),
@@ -360,7 +361,7 @@ NgPost::NgPost(int &argc, char *argv[]):
360361

361362
void NgPost::_startMonitoring(const QString &folderPath)
362363
{
363-
qDebug() << "Start Monitoring " << folderPath;
364+
qDebug() << "Start Monitoring " << folderPath << " (delay scan: " << FoldersMonitorForNewFiles::sMSleep << "ms)";
364365
_monitorThread = new QThread();
365366
_monitorThread->setObjectName("Monitoring");
366367
_folderMonitor = new FoldersMonitorForNewFiles(folderPath);
@@ -1419,7 +1420,8 @@ bool NgPost::parseCommandLine(int argc, char *argv[])
14191420
}
14201421
else
14211422
{
1422-
_cout << "[FolderMonitor] " << tr("start monitoring: ") << fi.absoluteFilePath() << "\n" << MB_FLUSH;
1423+
_cout << "[FolderMonitor] " << tr("start monitoring: ") << fi.absoluteFilePath()
1424+
<< " (delay: " << FoldersMonitorForNewFiles::sMSleep << "ms)\n" << MB_FLUSH;
14231425
isMonitoring = true;
14241426
if (_folderMonitor)
14251427
_folderMonitor->addFolder(fi.absoluteFilePath());
@@ -1964,6 +1966,14 @@ QString NgPost::_parseConfig(const QString &configPath)
19641966
if (val == "true" || val == "on" || val == "1")
19651967
_monitorIgnoreDir = true;
19661968
}
1969+
else if (opt == sOptionNames[Opt::MONITOR_SEC_DELAY_SCAN])
1970+
{
1971+
int nb = val.toInt(&ok);
1972+
if (ok && nb > 1 && nb <= 120) {
1973+
_monitorSecDelayScan = static_cast<ushort>(nb);
1974+
FoldersMonitorForNewFiles::sMSleep = _monitorSecDelayScan * 1000;
1975+
}
1976+
}
19671977
else if (opt == sOptionNames[Opt::NZB_RM_ACCENTS])
19681978
{
19691979
val = val.toLower();
@@ -2459,7 +2469,8 @@ void NgPost::_dumpParams() const
24592469

24602470
<< "\ninputDir: " << _inputDir << ", autoDelete: " << _delAuto
24612471
<< ", packAutoKeywords:" << _packAutoKeywords << ", autoClose: " << _autoCloseTabs
2462-
2472+
<< "\n, monitor delay: " << _monitorSecDelayScan << " ignore dir: " << _monitorIgnoreDir
2473+
<< " ext: " << _monitorExtensions
24632474
<< "\n\nfrom: " << _from.c_str() << ", genFrom: " << _genFrom << ", saveFrom: " << _saveFrom
24642475
<< ", groups: " << _grpList.join(",")
24652476
<< " policy: " << sGroupPolicies[_groupPolicy].toUpper()
@@ -2566,6 +2577,9 @@ void NgPost::saveConfig()
25662577
<< "\n"
25672578
<< tr("## for monitoring, ignore new incoming folders") << "\n"
25682579
<< (_monitorIgnoreDir ? "" : "#") << "MONITOR_IGNORE_DIR = true\n"
2580+
<< tr("## for monitoring, delay to check the size of an incoming file/folder to make sure it is fully arrived before posting it") << "\n"
2581+
<< tr("## must be between 1sec and 120sec (otherwise default: 1sec)") << "\n"
2582+
<< "MONITOR_SEC_DELAY_SCAN = " << _monitorSecDelayScan << "\n"
25692583
<< "\n\n"
25702584
<< tr("## Default folder to open to select files from the HMI") << "\n"
25712585
<< "inputDir = " << _inputDir << "\n"

src/NgPost.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class NgPost : public QObject, public CmdOrGuiApp
8181
DISP_PROGRESS, DEBUG, DEBUG_FULL, POST_HISTORY, FIELD_SEPARATOR, NZB_RM_ACCENTS,
8282
RESUME_WAIT, NO_RESUME_AUTO, SOCK_TIMEOUT, PREPARE_PACKING,
8383
INPUT, OUTPUT, NZB_PATH, THREAD, NZB_UPLOAD_URL, NZB_POST_CMD,
84-
MONITOR_FOLDERS, MONITOR_EXT, MONITOR_IGNORE_DIR,
84+
MONITOR_FOLDERS, MONITOR_EXT, MONITOR_IGNORE_DIR, MONITOR_SEC_DELAY_SCAN,
8585
MSG_ID, META, ARTICLE_SIZE, FROM, GROUPS, NB_RETRY, GEN_FROM,
8686
OBFUSCATE, INPUT_DIR, AUTO_DIR, MONITOR_DIR, DEL_AUTO,
8787
TMP_DIR, RAR_PATH, RAR_EXTRA, RAR_SIZE, RAR_MAX, KEEP_RAR,
@@ -198,6 +198,7 @@ class NgPost : public QObject, public CmdOrGuiApp
198198
bool _monitor_nzb_folders;
199199
QStringList _monitorExtensions;
200200
bool _monitorIgnoreDir;
201+
ushort _monitorSecDelayScan;
201202

202203
bool _keepRar;
203204
bool _packAuto;

0 commit comments

Comments
 (0)