diff --git a/ChangeLog b/ChangeLog index ac928d2d..dab6e6bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ * Fix power panic stuck at Resend * Fix startup issues on RPi 5 * Wait a bit for printer to finish moves after waking up from power panic + * Sync files upon Upload finish 0.8.0alpha4 * Support newer "//action" without the space diff --git a/prusa/link/web/files.py b/prusa/link/web/files.py index 414068b9..1f4e4ac4 100644 --- a/prusa/link/web/files.py +++ b/prusa/link/web/files.py @@ -1,6 +1,6 @@ """/api/v1/files endpoint handlers""" import logging -from os import listdir, replace, rmdir, unlink +from os import fsync, listdir, replace, rmdir, unlink from os.path import basename, exists, isdir, join, split from pathlib import Path from shutil import rmtree @@ -151,8 +151,11 @@ def file_info(req, storage, path=None): if child_type is not FileType.FOLDER.value: # Fill specific data for print files within children list if child_type is FileType.PRINT_FILE.value: - child.update(fill_printfile_data(child_path, child_os_path, - storage, simple=True)) + child.update( + fill_printfile_data(child_path, + child_os_path, + storage, + simple=True)) # Fill specific data for firmware files within children list elif child_type is FileType.FIRMWARE.value: @@ -230,7 +233,8 @@ def file_upload(req, storage, path): part_path = partfilepath(filename) transfer = app.daemon.prusa_link.printer.transfer - transfer.start(TransferType.FROM_CLIENT, filename, + transfer.start(TransferType.FROM_CLIENT, + filename, to_print=print_after_upload) transfer.size = req.content_length transfer.start_ts = monotonic() @@ -249,6 +253,8 @@ def file_upload(req, storage, path): data = req.read(block) else: data = b'' + temp.flush() + fsync(temp.fileno()) transfer.type = TransferType.NO_TRANSFER diff --git a/prusa/link/web/lib/files.py b/prusa/link/web/lib/files.py index 96a26cab..99f218bb 100644 --- a/prusa/link/web/lib/files.py +++ b/prusa/link/web/lib/files.py @@ -3,7 +3,7 @@ from functools import wraps from hashlib import md5 from io import FileIO -from os import statvfs +from os import fsync, statvfs from os.path import abspath, dirname, exists, join from time import sleep, time @@ -433,6 +433,8 @@ def write(self, data): return size def close(self): + self.flush() + fsync(self.fileno()) super().close() event_cb = app.daemon.prusa_link.printer.event_cb event_cb(Event.TRANSFER_FINISHED, diff --git a/prusa/link/web/upload.py b/prusa/link/web/upload.py deleted file mode 100644 index 4f98c901..00000000 --- a/prusa/link/web/upload.py +++ /dev/null @@ -1 +0,0 @@ -# from .lib.core import app diff --git a/ruff.toml b/ruff.toml index b3b47d5f..ef76386b 100644 --- a/ruff.toml +++ b/ruff.toml @@ -134,3 +134,5 @@ lint.ignore = [ "RUF015", # Prefer `next(iter(screen.lines()))` over single element slice "S104", # Possible binding to all interfaces¸ ] + +line-length = 79