Skip to content

Commit

Permalink
Sync files upon Upload finish
Browse files Browse the repository at this point in the history
* some little cleanup
  • Loading branch information
ondratu committed May 24, 2024
1 parent fc8cc62 commit b2c9fe5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions prusa/link/web/files.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand All @@ -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

Expand Down
4 changes: 3 additions & 1 deletion prusa/link/web/lib/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion prusa/link/web/upload.py

This file was deleted.

2 changes: 2 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b2c9fe5

Please sign in to comment.