|
2 | 2 | The tools that deals with files in the database |
3 | 3 | """ |
4 | 4 | from pathlib import Path |
5 | | -import os, shutil, json, platform, typing, uuid, time |
| 5 | +import os, shutil, json, platform, typing, uuid, time, sys |
6 | 6 | from typing import List, Union, TypedDict |
7 | 7 | import warnings |
| 8 | +import threading |
| 9 | + |
8 | 10 | from . import globalVar as G |
9 | 11 | from .utils import openFile, TimeUtils |
10 | 12 | from ..confReader import getConf, VERSION, getConfV |
@@ -199,6 +201,10 @@ def __init__(self, data_path): |
199 | 201 | self.path = data_path |
200 | 202 | self.base_name: str = os.path.split(data_path)[-1] |
201 | 203 | self._file_extension: str = "" # extension of the main document, "" for undefined / No file |
| 204 | + |
| 205 | + # a switch to trigger the logging of file modification time |
| 206 | + self._enable_log_modification_timestamp = True |
| 207 | + |
202 | 208 | self.init() |
203 | 209 |
|
204 | 210 | def init(self): |
@@ -464,8 +470,20 @@ def openFile(self): |
464 | 470 | if self.file_extension == ".hpack": |
465 | 471 | openTmp_hpack(self.file_p) |
466 | 472 | else: |
| 473 | + # Open file in MacOS will be treated as a file modification |
| 474 | + # so temporarily ban file observer log modification time |
| 475 | + if sys.platform == "darwin": |
| 476 | + self._enable_log_modification_timestamp = False |
| 477 | + |
467 | 478 | openFile(self.file_p) |
468 | | - # self._log() # change time modified. |
| 479 | + |
| 480 | + # maybe re-enable file observer log modification time |
| 481 | + def _restartLoggingModification(): |
| 482 | + # relax some time to open the file |
| 483 | + time.sleep(3) |
| 484 | + self._enable_log_modification_timestamp = True |
| 485 | + if sys.platform == "darwin": |
| 486 | + threading.Thread(target=_restartLoggingModification, args=(), daemon=True).start() |
469 | 487 | return True |
470 | 488 |
|
471 | 489 | def openMiscDir(self): |
@@ -499,7 +517,9 @@ def setWatch(self, status: bool = False): |
499 | 517 | self.logger.debug(f"setWatch (fm): Started file observer for {self.uuid}") |
500 | 518 |
|
501 | 519 | def _log(self) -> bool: |
502 | | - """log the modification info info file""" |
| 520 | + """log the modification time to the info file""" |
| 521 | + if not self._enable_log_modification_timestamp: |
| 522 | + return False |
503 | 523 | time_now = time.time() |
504 | 524 | if time_now - self._time_last_log < self.LOG_TOLERANCE_INTERVAL: |
505 | 525 | # Prevent multiple log at same time |
|
0 commit comments