Skip to content

Commit

Permalink
fix rename when SPIFFS_COMPAT is enabled; previously it wasn't attemp…
Browse files Browse the repository at this point in the history
…ting to create dst folder(s) and wasn't attempting to delete empty src folder(s)
  • Loading branch information
BrianPugh committed Apr 4, 2022
1 parent 20f14d2 commit 29341d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 10 additions & 0 deletions example/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_demo_esp_littlefs.csv"

#
# Serial flasher config
#
CONFIG_ESPTOOLPY_BAUD_921600B=y
CONFIG_ESPTOOLPY_COMPRESSED=y
CONFIG_ESPTOOLPY_MONITOR_BAUD_CONSOLE=y

# BOOTLOADER
CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
15 changes: 14 additions & 1 deletion src/esp_littlefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1415,15 +1415,28 @@ static int vfs_littlefs_rename(void* ctx, const char *src, const char *dst) {
return -1;
}

#if CONFIG_LITTLEFS_SPIFFS_COMPAT
/* Create all parent directories to dst (if necessary) */
ESP_LOGV(TAG, "LITTLEFS_SPIFFS_COMPAT attempting to create all directories for %s", src);
mkdirs(efs, dst);
#endif

res = lfs_rename(efs->fs, src, dst);
sem_give(efs);
if (res < 0) {
errno = lfs_errno_remap(res);
sem_give(efs);
ESP_LOGV(TAG, "Failed to rename \"%s\" -> \"%s\". Error %s (%d)",
src, dst, esp_littlefs_errno(res), res);
return -1;
}

#if CONFIG_LITTLEFS_SPIFFS_COMPAT
/* Attempt to delete all parent directories from src that are empty */
rmdirs(efs, src);
#endif // CONFIG_LITTLEFS_SPIFFS_COMPAT

sem_give(efs);

return 0;
}

Expand Down

0 comments on commit 29341d0

Please sign in to comment.