From b8c7b3cb5f65a1dab5142e25a342b2ccccd19275 Mon Sep 17 00:00:00 2001 From: Luxferre Date: Wed, 24 Dec 2025 17:35:06 +0200 Subject: [PATCH] upgraded copy method --- deck/fs.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/deck/fs.py b/deck/fs.py index c672103..b1d990d 100644 --- a/deck/fs.py +++ b/deck/fs.py @@ -40,12 +40,27 @@ def umount_sd(path='/sd'): sd_ok = False return sd_ok -# TODO: switch to buffered copying to avoid RAM overflow -def copy(p1, p2): - with open(p1, 'rb') as f1: - content = f1.read() - with open(p2, 'wb') as f2: - f2.write(content) +def copy(source_path, dest_path, buffer_size=8192): + """ + Copies a file from source_path to dest_path + """ + try: + with open(source_path, "rb") as src: + with open(dest_path, "wb") as dst: + while True: + # Read a chunk from the source + buffer = src.read(buffer_size) + if not buffer: + break + # Write the chunk to the destination + dst.write(buffer) + return True + except OSError as e: + print(f"Error copying file: {e}") + return False + except Exception as e: + print(f"An unexpected error occurred: {e}") + return False cp = copy # shortcut export