| 115 | #ifdef HAS_SDCARD |
| 116 | |
| 117 | void copyBetweenFS(FS& sourceFS, const char* source_path, FS& targetFS) { |
| 118 | File root = sourceFS.open(source_path); |
| 119 | char next_path[128]; |
| 120 | |
| 121 | if (root.isDirectory()) { |
| 122 | if (!contentFS->exists(root.path())) { |
| 123 | if (!contentFS->mkdir(root.path())) { |
| 124 | Serial.print("Failed to create directory "); |
| 125 | Serial.println(root.path()); |
| 126 | return; |
| 127 | } |
| 128 | } |
| 129 | File file = root.openNextFile(); |
| 130 | while (file) { |
| 131 | if (file.isDirectory()) { |
| 132 | sprintf(next_path, "%s/%s\0", root.path(), file.path()); |
| 133 | |
| 134 | copyBetweenFS(sourceFS, file.path(), targetFS); |
| 135 | } else { |
| 136 | xSemaphoreTake(fsMutex, portMAX_DELAY); |
| 137 | File target = contentFS->open(file.path(), "w"); |
| 138 | if (target) { |
| 139 | copyFile(file, target); |
| 140 | target.close(); |
| 141 | file.close(); |
| 142 | xSemaphoreGive(fsMutex); |
| 143 | } else { |
| 144 | xSemaphoreGive(fsMutex); |
| 145 | Serial.print("Couldn't create high target file"); |
| 146 | Serial.println(file.path()); |
| 147 | return; |
| 148 | } |
| 149 | } |
| 150 | file = root.openNextFile(); |
| 151 | } |
| 152 | } else { |
| 153 | xSemaphoreTake(fsMutex, portMAX_DELAY); |
| 154 | File target = contentFS->open(root.path(), "w"); |
| 155 | if (target) { |
| 156 | copyFile(root, target); |
| 157 | target.close(); |
| 158 | xSemaphoreGive(fsMutex); |
| 159 | } else { |
| 160 | xSemaphoreGive(fsMutex); |
| 161 | Serial.print("Couldn't create target file "); |
| 162 | Serial.println(root.path()); |
| 163 | return; |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | void copyIfNeeded(const char* path) { |
| 169 | if (!contentFS->exists(path) && LittleFS.exists(path)) { |