Skip to content

feat: feat(print): copy USB gcode to local storage and print the local copy - #372

Open
gmmcosta15 wants to merge 5 commits into
devfrom
feat/usb-local-print
Open

gmmcosta15 wants to merge 5 commits into
devfrom
feat/usb-local-print

Conversation

@gmmcosta15

Copy link
Copy Markdown
Collaborator

Description

  • Feature
  • Bug Fix
  • Code Refactor
  • Documentation

Printing a file from a USB drive now copies it into ~/printer_data/gcodes/ and prints the local copy, so removing the drive mid-print no longer kills the job. The copy is atomic and only starts printing once Moonraker (and Happy Hare's preprocessor) has finished with it. Reprinting the same USB file reuses the existing local copy instead of making a new one.

Changes

  • New lib/utils/usb_import.py: validates the USB path (mounted drive, no symlink or .. escape, .gcode only), checks free space, copies via a fsynced temp file in printer_data/.usb_import/ and os.replace, runs off the UI thread as UsbImportTask
  • Reuse: an index in .usb_import/index.json maps each USB file (name, size, head and tail hash) to its processed local copy; byte-identical same-name files are reused too, a different file with the same name gets a _n suffix
  • printTab.start_print routes USB files through the import; a new copy prints after Moonraker's create_file for it, or after a 120 s timeout
  • Import errors show a notification and never start a print
  • Unit tests for the import module and the print-start flow

Motivation

Prints started from a USB drive read the file from the drive for the whole job, so pulling it or a loose connection ended the print. Happy Hare also rewrites new gcodes, so printing before it finishes left Klipper reading a deleted file.

@gmmcosta15
gmmcosta15 requested a review from a team October 30, 2026 10:21
@gmmcosta15 gmmcosta15 added the enhancement New feature or improvement label Oct 30, 2026
@gmmcosta15 gmmcosta15 self-assigned this Oct 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant