Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 SD storage doesn't use SD.rename method to rename a file #44

Closed
scuba-hacker opened this issue Sep 9, 2023 · 2 comments
Closed

Comments

@scuba-hacker
Copy link

scuba-hacker commented Sep 9, 2023

For the use case of ESP32 using SD storage: (particularly an issue for files that are very large, eg tens of MB like large wav files used in audio player use-case)

In FTPServer.h the rename file method is not using the SD.rename method and instead the code makes a complete copy of the file, which is particularly an issue for large files as the copy method of rename takes a long time and hangs the FTP client, causing a disconnect. (Both Cyberduck and FileZilla).

(I can't get the code block to allow newlines...)

I needed to make two changes:

FTPServer.h

Existing code in FTPServer.h:

#if STORAGE_TYPE == STORAGE_SD || STORAGE_TYPE == STORAGE_SD_MMC
bool rename( const char * path, const char * newpath );
#else
bool rename( const char * path, const char * newpath ) { return STORAGE_MANAGER.rename( path, newpath ); };
#endif

Code change:

#if (STORAGE_TYPE == STORAGE_SD || STORAGE_TYPE == STORAGE_SD_MMC)
#if defined(ESP32))
bool rename( const char * path, const char * newpath ) { return STORAGE_MANAGER.rename( path, newpath ); };
#else
bool rename( const char * path, const char * newpath );
#endif
#else
bool rename( const char * path, const char * newpath ) { return STORAGE_MANAGER.rename( path, newpath ); };
#endif

FTPServer.cpp

Existing code:

#if (STORAGE_TYPE == STORAGE_SD || STORAGE_TYPE == STORAGE_SD_MMC)
bool FtpServer::rename( const char * path, const char * newpath ){
FTP_FILE myFileIn = STORAGE_MANAGER.open(path, FILE_READ);
FTP_FILE myFileOut = STORAGE_MANAGER.open(newpath, FILE_WRITE);

Code change:

#if !defined(ESP32) && (STORAGE_TYPE == STORAGE_SD || STORAGE_TYPE == STORAGE_SD_MMC)
bool FtpServer::rename( const char * path, const char * newpath ){
FTP_FILE myFileIn = STORAGE_MANAGER.open(path, FILE_READ);
FTP_FILE myFileOut = STORAGE_MANAGER.open(newpath, FILE_WRITE);

@xreef
Copy link
Owner

xreef commented Oct 17, 2023

I add the change, thanks scuba.

@xreef xreef closed this as completed Oct 17, 2023
@scuba-hacker
Copy link
Author

Nice one, thanks @xreef for a great library. I find it the easiest way to get files uploaded to the Adafruit SPI Flash SD Card (which uses onboard flash and presents it as though it had a physical SD card).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants