Merge branch 'main' into task/BIT-26141-fix-test-endpoint
This commit is contained in:
commit
48d8ef2952
5 files changed
+360
-23
No files matched your search
@@ -37,6 +37,7 @@ from forwarder.services.sync_service import (
|
||||
is_missing_from_mailbox_error,
|
||||
)
|
||||
from forwarder.webdav.client import (
|
||||
MIN_WEBDAV_FILE_BYTES,
|
||||
WebdavConfig,
|
||||
WebdavNotFoundError,
|
||||
download_file,
|
||||
@@ -44,12 +45,47 @@ from forwarder.webdav.client import (
|
||||
list_files,
|
||||
normalize_webdav_folder_path,
|
||||
parse_webdav_message_key,
|
||||
webdav_bytes_below_min_size,
|
||||
webdav_file_below_min_size,
|
||||
webdav_file_matches_min_year,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _skip_too_small_webdav_file(
|
||||
db: Session,
|
||||
*,
|
||||
account_id: int,
|
||||
message_key: str,
|
||||
folder_label: str,
|
||||
uid: str,
|
||||
subject: str,
|
||||
from_addr: str,
|
||||
date: str,
|
||||
size_bytes: int,
|
||||
processed_keys: set[str],
|
||||
result: SyncResult,
|
||||
) -> None:
|
||||
error_message = (
|
||||
f"skipped: file too small ({size_bytes} bytes, min {MIN_WEBDAV_FILE_BYTES})"
|
||||
)
|
||||
_upsert_message(
|
||||
db,
|
||||
account_id=account_id,
|
||||
message_key=message_key,
|
||||
folder=folder_label,
|
||||
uid=uid,
|
||||
subject=subject,
|
||||
from_addr=from_addr,
|
||||
date=date,
|
||||
status=MessageStatus.skipped,
|
||||
error_message=error_message,
|
||||
)
|
||||
processed_keys.add(message_key)
|
||||
result.messages_skipped += 1
|
||||
|
||||
|
||||
def resolve_webdav_config(account: Account) -> WebdavConfig:
|
||||
if not account.webdav_url or not account.webdav_user or not account.webdav_password_encrypted:
|
||||
raise ValueError("WebDAV url, user and password are required")
|
||||
@@ -120,6 +156,32 @@ def sync_webdav_account(
|
||||
result.messages_skipped += 1
|
||||
continue
|
||||
|
||||
uid = remote_file.etag or str(remote_file.size)
|
||||
subject = filename
|
||||
from_addr = source_label = f"webdav:{account.webdav_url}"
|
||||
date = remote_file.modified or ""
|
||||
|
||||
if webdav_file_below_min_size(remote_file):
|
||||
_skip_too_small_webdav_file(
|
||||
db,
|
||||
account_id=account_id,
|
||||
message_key=message_key,
|
||||
folder_label=folder_label,
|
||||
uid=uid,
|
||||
subject=subject,
|
||||
from_addr=from_addr,
|
||||
date=date,
|
||||
size_bytes=remote_file.size,
|
||||
processed_keys=processed_keys,
|
||||
result=result,
|
||||
)
|
||||
logger.info(
|
||||
"WebDAV skipped (too small, PROPFIND): %s (%d bytes)",
|
||||
remote_file.relative_path,
|
||||
remote_file.size,
|
||||
)
|
||||
continue
|
||||
|
||||
try:
|
||||
data = download_file(webdav_config, remote_file.relative_path)
|
||||
except WebdavNotFoundError as exc:
|
||||
@@ -131,12 +193,28 @@ def sync_webdav_account(
|
||||
logger.error("WebDAV download failed %s: %s", remote_file.relative_path, exc)
|
||||
continue
|
||||
|
||||
if webdav_bytes_below_min_size(data):
|
||||
_skip_too_small_webdav_file(
|
||||
db,
|
||||
account_id=account_id,
|
||||
message_key=message_key,
|
||||
folder_label=folder_label,
|
||||
uid=uid,
|
||||
subject=subject,
|
||||
from_addr=from_addr,
|
||||
date=date,
|
||||
size_bytes=len(data),
|
||||
processed_keys=processed_keys,
|
||||
result=result,
|
||||
)
|
||||
logger.info(
|
||||
"WebDAV skipped (too small): %s (%d bytes)",
|
||||
remote_file.relative_path,
|
||||
len(data),
|
||||
)
|
||||
continue
|
||||
|
||||
result.messages_matched += 1
|
||||
source_label = f"webdav:{account.webdav_url}"
|
||||
subject = filename
|
||||
from_addr = source_label
|
||||
date = remote_file.modified or ""
|
||||
uid = remote_file.etag or str(remote_file.size)
|
||||
|
||||
if dry_run:
|
||||
message_row = _upsert_message(
|
||||
@@ -315,6 +393,17 @@ def retry_webdav_message(db: Session, message: Message, account: Account) -> Mes
|
||||
)
|
||||
raise MessageMissingFromMailboxError(marked, str(exc)) from exc
|
||||
|
||||
if webdav_bytes_below_min_size(data):
|
||||
message.status = MessageStatus.skipped
|
||||
message.error_message = (
|
||||
f"skipped: file too small ({len(data)} bytes, min {MIN_WEBDAV_FILE_BYTES})"
|
||||
)
|
||||
message.updated_at = datetime.now(timezone.utc)
|
||||
db.commit()
|
||||
db.refresh(message)
|
||||
logger.info("WebDAV retry skipped (too small): %s", relative_path)
|
||||
return message
|
||||
|
||||
if account.delivery_mode == DeliveryMode.smtp and smtp_config is not None:
|
||||
smtp = create_smtp_client(smtp_config)
|
||||
elif bizdocs_password:
|
||||
|
||||
@@ -14,15 +14,23 @@ import httpx
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Reject HTML stubs / placeholders before download when PROPFIND reports size.
|
||||
MIN_WEBDAV_FILE_BYTES = 4 * 1024
|
||||
|
||||
OC_NS = "{http://owncloud.org/ns}"
|
||||
NC_NS = "{http://nextcloud.org/ns}"
|
||||
DAV_NS = "{DAV:}"
|
||||
|
||||
PROPFIND_BODY = b"""<?xml version="1.0" encoding="utf-8"?>
|
||||
<D:propfind xmlns:D="DAV:">
|
||||
<D:propfind xmlns:D="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">
|
||||
<D:prop>
|
||||
<D:displayname/>
|
||||
<D:getetag/>
|
||||
<D:getcontentlength/>
|
||||
<D:getlastmodified/>
|
||||
<D:creationdate/>
|
||||
<oc:creation-time/>
|
||||
<nc:creation-time/>
|
||||
<D:resourcetype/>
|
||||
</D:prop>
|
||||
</D:propfind>
|
||||
@@ -46,6 +54,8 @@ class WebdavFile:
|
||||
etag: str
|
||||
modified: str
|
||||
created: str
|
||||
oc_creation_time: str
|
||||
nc_creation_time: str
|
||||
size: int
|
||||
|
||||
|
||||
@@ -134,14 +144,39 @@ def parse_webdav_iso_date(value: str) -> datetime | None:
|
||||
|
||||
|
||||
def webdav_file_reference_date(file: WebdavFile) -> datetime | None:
|
||||
if file.created:
|
||||
created = parse_webdav_iso_date(file.created)
|
||||
if created is not None:
|
||||
return created
|
||||
created = parse_webdav_http_date(file.created)
|
||||
if created is not None:
|
||||
return created
|
||||
return parse_webdav_http_date(file.modified)
|
||||
"""Reference date for year filtering.
|
||||
|
||||
Nextcloud often returns DAV:creationdate as Unix epoch (1970) for bulk-imported
|
||||
files. Prefer getlastmodified (upload time on server), then oc/nc creation-time,
|
||||
then creationdate when trustworthy.
|
||||
"""
|
||||
modified = parse_webdav_http_date(file.modified)
|
||||
if modified is not None:
|
||||
return modified
|
||||
|
||||
for raw in (file.oc_creation_time, file.nc_creation_time, file.created):
|
||||
if not raw:
|
||||
continue
|
||||
parsed = parse_webdav_iso_date(raw)
|
||||
if parsed is not None and not _is_untrusted_webdav_date(parsed):
|
||||
return parsed
|
||||
parsed = parse_webdav_http_date(raw)
|
||||
if parsed is not None and not _is_untrusted_webdav_date(parsed):
|
||||
return parsed
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def _is_untrusted_webdav_date(value: datetime) -> bool:
|
||||
"""Nextcloud often reports missing creation as Unix epoch (1970)."""
|
||||
return value.year <= 1971
|
||||
|
||||
|
||||
def webdav_folder_year_meets_min_year(relative_path: str, min_year: int) -> bool:
|
||||
folder_year = webdav_year_folder(relative_path)
|
||||
if folder_year is None:
|
||||
return False
|
||||
return int(folder_year) >= min_year
|
||||
|
||||
|
||||
def webdav_min_year_cutoff(min_year: int) -> datetime:
|
||||
@@ -151,12 +186,33 @@ def webdav_min_year_cutoff(min_year: int) -> datetime:
|
||||
def webdav_file_matches_min_year(file: WebdavFile, min_year: int | None) -> bool:
|
||||
if min_year is None:
|
||||
return True
|
||||
|
||||
if webdav_folder_year_meets_min_year(file.relative_path, min_year):
|
||||
return True
|
||||
|
||||
reference_date = webdav_file_reference_date(file)
|
||||
if reference_date is None:
|
||||
return False
|
||||
return reference_date >= webdav_min_year_cutoff(min_year)
|
||||
|
||||
|
||||
def webdav_file_below_min_size(
|
||||
file: WebdavFile,
|
||||
min_bytes: int = MIN_WEBDAV_FILE_BYTES,
|
||||
) -> bool:
|
||||
"""True when PROPFIND size is known and below min_bytes (size 0 = unknown)."""
|
||||
if file.size <= 0:
|
||||
return False
|
||||
return file.size < min_bytes
|
||||
|
||||
|
||||
def webdav_bytes_below_min_size(
|
||||
data: bytes,
|
||||
min_bytes: int = MIN_WEBDAV_FILE_BYTES,
|
||||
) -> bool:
|
||||
return len(data) < min_bytes
|
||||
|
||||
|
||||
def _client(config: WebdavConfig, *, timeout: float = 60.0) -> httpx.Client:
|
||||
return httpx.Client(
|
||||
timeout=timeout,
|
||||
@@ -167,13 +223,30 @@ def _client(config: WebdavConfig, *, timeout: float = 60.0) -> httpx.Client:
|
||||
)
|
||||
|
||||
|
||||
def _element_text(parent: element_tree.Element, tag: str) -> str:
|
||||
node = parent.find(f"{DAV_NS}{tag}")
|
||||
def _element_text(parent: element_tree.Element, tag: str, ns: str = DAV_NS) -> str:
|
||||
node = parent.find(f"{ns}{tag}")
|
||||
if node is None or node.text is None:
|
||||
return ""
|
||||
return node.text.strip()
|
||||
|
||||
|
||||
def _propstat_ok(propstat: element_tree.Element) -> bool:
|
||||
status = _element_text(propstat, "status")
|
||||
if not status:
|
||||
return True
|
||||
return " 200 " in status or status.endswith(" 200 OK")
|
||||
|
||||
|
||||
def _select_propstat(response_elem: element_tree.Element) -> element_tree.Element | None:
|
||||
propstats = response_elem.findall(f"{DAV_NS}propstat")
|
||||
if not propstats:
|
||||
return None
|
||||
for propstat in propstats:
|
||||
if _propstat_ok(propstat):
|
||||
return propstat
|
||||
return propstats[0]
|
||||
|
||||
|
||||
def _is_collection(response_elem: element_tree.Element) -> bool:
|
||||
resource_type = response_elem.find(f"{DAV_NS}propstat/{DAV_NS}prop/{DAV_NS}resourcetype")
|
||||
if resource_type is None:
|
||||
@@ -217,7 +290,7 @@ def _parse_propfind_response(root_url: str, content: bytes) -> list[WebdavFile]:
|
||||
if name.startswith("."):
|
||||
continue
|
||||
|
||||
propstat = response_elem.find(f"{DAV_NS}propstat")
|
||||
propstat = _select_propstat(response_elem)
|
||||
if propstat is None:
|
||||
continue
|
||||
prop = propstat.find(f"{DAV_NS}prop")
|
||||
@@ -227,6 +300,8 @@ def _parse_propfind_response(root_url: str, content: bytes) -> list[WebdavFile]:
|
||||
etag = _element_text(prop, "getetag").strip('"')
|
||||
modified = _element_text(prop, "getlastmodified")
|
||||
created = _element_text(prop, "creationdate")
|
||||
oc_creation_time = _element_text(prop, "creation-time", OC_NS)
|
||||
nc_creation_time = _element_text(prop, "creation-time", NC_NS)
|
||||
size_text = _element_text(prop, "getcontentlength")
|
||||
try:
|
||||
size = int(size_text) if size_text else 0
|
||||
@@ -241,6 +316,8 @@ def _parse_propfind_response(root_url: str, content: bytes) -> list[WebdavFile]:
|
||||
etag=etag,
|
||||
modified=modified,
|
||||
created=created,
|
||||
oc_creation_time=oc_creation_time,
|
||||
nc_creation_time=nc_creation_time,
|
||||
size=size,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from apscheduler.schedulers.blocking import BlockingScheduler
|
||||
from apscheduler.triggers.interval import IntervalTrigger
|
||||
@@ -70,6 +71,13 @@ def _forward_queue_job() -> None:
|
||||
db.close()
|
||||
|
||||
|
||||
def _interval_trigger_minutes(trigger: IntervalTrigger) -> int | None:
|
||||
interval = getattr(trigger, "interval", None)
|
||||
if interval is None:
|
||||
return None
|
||||
return int(interval.total_seconds() // 60)
|
||||
|
||||
|
||||
def _refresh_account_schedules(scheduler: BlockingScheduler, *, default_interval: int) -> None:
|
||||
"""Reconcile APScheduler jobs with enabled accounts in the database."""
|
||||
db = get_session_factory()()
|
||||
@@ -79,15 +87,21 @@ def _refresh_account_schedules(scheduler: BlockingScheduler, *, default_interval
|
||||
for account in accounts:
|
||||
enabled_ids.add(account.id)
|
||||
interval = account.sync_interval_minutes or default_interval
|
||||
job_id = _account_job_id(account.id)
|
||||
existing = scheduler.get_job(job_id)
|
||||
if existing is not None and _interval_trigger_minutes(existing.trigger) == interval:
|
||||
continue
|
||||
|
||||
scheduler.add_job(
|
||||
_sync_job,
|
||||
trigger=IntervalTrigger(minutes=interval),
|
||||
args=[account.id],
|
||||
id=_account_job_id(account.id),
|
||||
id=job_id,
|
||||
replace_existing=True,
|
||||
max_instances=1,
|
||||
next_run_time=datetime.now(timezone.utc),
|
||||
)
|
||||
logger.debug(
|
||||
logger.info(
|
||||
"Schedule ensured for account %s (%s) every %s minutes",
|
||||
account.id,
|
||||
account.name,
|
||||
|
||||
+124
-2
@@ -1,6 +1,7 @@
|
||||
"""Tests for WebDAV client helpers and PROPFIND parsing."""
|
||||
|
||||
from forwarder.webdav.client import (
|
||||
MIN_WEBDAV_FILE_BYTES,
|
||||
WebdavConfig,
|
||||
WebdavFile,
|
||||
_parse_propfind_response,
|
||||
@@ -8,6 +9,8 @@ from forwarder.webdav.client import (
|
||||
get_webdav_message_key,
|
||||
normalize_webdav_folder_path,
|
||||
parse_webdav_message_key,
|
||||
webdav_bytes_below_min_size,
|
||||
webdav_file_below_min_size,
|
||||
webdav_file_matches_min_year,
|
||||
webdav_file_reference_date,
|
||||
)
|
||||
@@ -84,19 +87,138 @@ def _sample_file(*, modified: str = "", created: str = "", path: str = "a.pdf")
|
||||
etag="1",
|
||||
modified=modified,
|
||||
created=created,
|
||||
oc_creation_time="",
|
||||
nc_creation_time="",
|
||||
size=100,
|
||||
)
|
||||
|
||||
|
||||
def test_webdav_file_matches_min_year_by_creation_date():
|
||||
old = _sample_file(created="2024-06-01T10:00:00Z", modified="Mon, 01 Jan 2026 10:00:00 GMT")
|
||||
assert webdav_file_reference_date(old).year == 2024
|
||||
assert not webdav_file_matches_min_year(old, 2025)
|
||||
assert webdav_file_reference_date(old).year == 2026
|
||||
assert webdav_file_matches_min_year(old, 2025)
|
||||
|
||||
recent = _sample_file(modified="Mon, 15 Jun 2025 12:00:00 GMT")
|
||||
assert webdav_file_matches_min_year(recent, 2025)
|
||||
|
||||
|
||||
def test_webdav_file_reference_date_prefers_modified_over_epoch_creation():
|
||||
nextcloud_import = WebdavFile(
|
||||
relative_path="Faturas/2025/01_Janeiro/invoice.pdf",
|
||||
name="invoice.pdf",
|
||||
href="/invoice.pdf",
|
||||
etag="1",
|
||||
modified="Mon, 06 Jan 2025 13:38:04 GMT",
|
||||
created="1970-01-01T00:00:00+00:00",
|
||||
oc_creation_time="",
|
||||
nc_creation_time="",
|
||||
size=50000,
|
||||
)
|
||||
assert webdav_file_reference_date(nextcloud_import).year == 2025
|
||||
assert webdav_file_matches_min_year(nextcloud_import, 2025)
|
||||
|
||||
|
||||
def test_webdav_file_matches_min_year_by_folder_when_epoch_date():
|
||||
epoch_in_2025_folder = WebdavFile(
|
||||
relative_path="Faturas/2025/01_Janeiro/invoice.pdf",
|
||||
name="invoice.pdf",
|
||||
href="/invoice.pdf",
|
||||
etag="1",
|
||||
modified="",
|
||||
created="1970-01-01T00:00:00+00:00",
|
||||
oc_creation_time="",
|
||||
nc_creation_time="",
|
||||
size=50000,
|
||||
)
|
||||
assert webdav_file_matches_min_year(epoch_in_2025_folder, 2025)
|
||||
|
||||
epoch_in_2024_folder = WebdavFile(
|
||||
relative_path="Faturas/2024/invoice.pdf",
|
||||
name="invoice.pdf",
|
||||
href="/invoice.pdf",
|
||||
etag="1",
|
||||
modified="",
|
||||
created="1970-01-01T00:00:00+00:00",
|
||||
oc_creation_time="",
|
||||
nc_creation_time="",
|
||||
size=50000,
|
||||
)
|
||||
assert not webdav_file_matches_min_year(epoch_in_2024_folder, 2025)
|
||||
|
||||
|
||||
def test_webdav_min_file_size():
|
||||
assert MIN_WEBDAV_FILE_BYTES == 4096
|
||||
small = WebdavFile(
|
||||
relative_path="stub.pdf",
|
||||
name="stub.pdf",
|
||||
href="/stub.pdf",
|
||||
etag="1",
|
||||
modified="",
|
||||
created="",
|
||||
oc_creation_time="",
|
||||
nc_creation_time="",
|
||||
size=1997,
|
||||
)
|
||||
assert webdav_file_below_min_size(small)
|
||||
unknown = WebdavFile(
|
||||
relative_path="x.pdf",
|
||||
name="x.pdf",
|
||||
href="/x.pdf",
|
||||
etag="1",
|
||||
modified="",
|
||||
created="",
|
||||
oc_creation_time="",
|
||||
nc_creation_time="",
|
||||
size=0,
|
||||
)
|
||||
assert not webdav_file_below_min_size(unknown)
|
||||
large = WebdavFile(
|
||||
relative_path="invoice.pdf",
|
||||
name="invoice.pdf",
|
||||
href="/invoice.pdf",
|
||||
etag="1",
|
||||
modified="",
|
||||
created="",
|
||||
oc_creation_time="",
|
||||
nc_creation_time="",
|
||||
size=5000,
|
||||
)
|
||||
assert not webdav_file_below_min_size(large)
|
||||
assert webdav_bytes_below_min_size(b"x" * 100)
|
||||
assert not webdav_bytes_below_min_size(b"x" * MIN_WEBDAV_FILE_BYTES)
|
||||
|
||||
|
||||
PROPFIND_MULTI_PROPSTAT = b"""<?xml version="1.0" encoding="utf-8"?>
|
||||
<D:multistatus xmlns:D="DAV:">
|
||||
<D:response>
|
||||
<D:href>/remote.php/dav/files/user/Faturas/doc.pdf</D:href>
|
||||
<D:propstat>
|
||||
<D:prop><D:creationdate/></D:prop>
|
||||
<D:status>HTTP/1.1 404 Not Found</D:status>
|
||||
</D:propstat>
|
||||
<D:propstat>
|
||||
<D:prop>
|
||||
<D:getlastmodified>Mon, 15 Jun 2025 12:00:00 GMT</D:getlastmodified>
|
||||
<D:creationdate>1970-01-01T00:00:00+00:00</D:creationdate>
|
||||
<D:getcontentlength>5000</D:getcontentlength>
|
||||
<D:getetag>"x"</D:getetag>
|
||||
<D:resourcetype/>
|
||||
</D:prop>
|
||||
<D:status>HTTP/1.1 200 OK</D:status>
|
||||
</D:propstat>
|
||||
</D:response>
|
||||
</D:multistatus>
|
||||
"""
|
||||
|
||||
|
||||
def test_parse_propfind_uses_ok_propstat():
|
||||
root = "https://cloud.example.com/remote.php/dav/files/user/Faturas/"
|
||||
files = _parse_propfind_response(root, PROPFIND_MULTI_PROPSTAT)
|
||||
assert len(files) == 1
|
||||
assert files[0].modified == "Mon, 15 Jun 2025 12:00:00 GMT"
|
||||
assert webdav_file_reference_date(files[0]).year == 2025
|
||||
|
||||
|
||||
def test_parse_propfind_response():
|
||||
root = "https://cloud.example.com/remote.php/dav/files/user/Faturas/"
|
||||
files = _parse_propfind_response(root, PROPFIND_SAMPLE)
|
||||
|
||||
@@ -16,8 +16,10 @@ from forwarder.webdav.client import (
|
||||
get_webdav_message_key,
|
||||
list_files,
|
||||
normalize_webdav_folder_path,
|
||||
parse_webdav_message_key,
|
||||
webdav_file_matches_min_year,
|
||||
webdav_file_reference_date,
|
||||
webdav_folder_year_meets_min_year,
|
||||
)
|
||||
|
||||
|
||||
@@ -28,13 +30,18 @@ def main() -> int:
|
||||
"--min-year",
|
||||
type=int,
|
||||
default=2025,
|
||||
help="Minimum file date year (creation or last-modified) — default 2025",
|
||||
help="Minimum year — folder path (e.g. /2025/) or file date when no folder year",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--mark-skipped",
|
||||
action="store_true",
|
||||
help="Insert skipped records for files outside allowed years",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--requeue-folder-years",
|
||||
action="store_true",
|
||||
help="Delete cutoff-skip records for files in min-year+ folders so sync re-sends them",
|
||||
)
|
||||
parser.add_argument("--dry-run", action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -58,7 +65,8 @@ def main() -> int:
|
||||
skip = len(files) - keep
|
||||
|
||||
print(f"Account {account.id} ({account.name}): {len(files)} file(s) listed")
|
||||
print(f"Min year (by file date): {args.min_year} → keep {keep}, skip {skip}")
|
||||
print(f"Min year: {args.min_year} → keep {keep}, skip {skip}")
|
||||
print("(Folder year in path takes priority over WebDAV dates, including 1970 epoch.)")
|
||||
print("By file date year:")
|
||||
for year in sorted(by_year):
|
||||
flag = "KEEP" if int(year) >= args.min_year else "SKIP"
|
||||
@@ -66,6 +74,33 @@ def main() -> int:
|
||||
if undated:
|
||||
print(f" (no date from WebDAV): {undated}")
|
||||
|
||||
if args.requeue_folder_years:
|
||||
from forwarder.db.models import Message
|
||||
|
||||
cutoff_msg = "skipped: file date before cutoff"
|
||||
candidates = (
|
||||
db.query(Message)
|
||||
.filter(
|
||||
Message.account_id == account.id,
|
||||
Message.error_message == cutoff_msg,
|
||||
)
|
||||
.all()
|
||||
)
|
||||
to_delete = []
|
||||
for message in candidates:
|
||||
relative_path = parse_webdav_message_key(message.message_key)
|
||||
if relative_path and webdav_folder_year_meets_min_year(
|
||||
relative_path, args.min_year
|
||||
):
|
||||
to_delete.append(message)
|
||||
if args.dry_run:
|
||||
print(f"Would requeue {len(to_delete)} file(s) from {args.min_year}+ folders")
|
||||
else:
|
||||
for message in to_delete:
|
||||
db.delete(message)
|
||||
db.commit()
|
||||
print(f"Requeued {len(to_delete)} file(s) — next sync will forward them")
|
||||
|
||||
if not args.mark_skipped:
|
||||
return 0
|
||||
|
||||
|
||||
Reference in new issue
Block a user