MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / handleMove

Method handleMove

src/network/CrossPointWebServer.cpp:885–976  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

883}
884
885void CrossPointWebServer::handleMove() const {
886 if (!server->hasArg("path") || !server->hasArg("dest")) {
887 server->send(400, "text/plain", "Missing path or destination");
888 return;
889 }
890
891 String itemPath = normalizeWebPath(server->arg("path"));
892 String destPath = normalizeWebPath(server->arg("dest"));
893
894 if (itemPath.isEmpty() || itemPath == "/") {
895 server->send(400, "text/plain", "Invalid path");
896 return;
897 }
898 if (destPath.isEmpty()) {
899 server->send(400, "text/plain", "Invalid destination");
900 return;
901 }
902
903 const String itemName = itemPath.substring(itemPath.lastIndexOf('/') + 1);
904 if (isProtectedItemName(itemName)) {
905 server->send(403, "text/plain", "Cannot move protected item");
906 return;
907 }
908 if (destPath != "/") {
909 const String destName = destPath.substring(destPath.lastIndexOf('/') + 1);
910 if (isProtectedItemName(destName)) {
911 server->send(403, "text/plain", "Cannot move into protected folder");
912 return;
913 }
914 }
915
916 if (!Storage.exists(itemPath.c_str())) {
917 server->send(404, "text/plain", "Item not found");
918 return;
919 }
920
921 HalFile file = Storage.open(itemPath.c_str());
922 if (!file) {
923 server->send(500, "text/plain", "Failed to open file");
924 return;
925 }
926 if (file.isDirectory()) {
927 file.close();
928 server->send(400, "text/plain", "Only files can be moved");
929 return;
930 }
931
932 if (!Storage.exists(destPath.c_str())) {
933 file.close();
934 server->send(404, "text/plain", "Destination not found");
935 return;
936 }
937 HalFile destDir = Storage.open(destPath.c_str());
938 if (!destDir || !destDir.isDirectory()) {
939 if (destDir) {
940 destDir.close();
941 }
942 file.close();

Callers

nothing calls this directly

Calls 9

normalizeWebPathFunction · 0.85
isProtectedItemNameFunction · 0.85
clearBookCacheFunction · 0.85
existsMethod · 0.80
isDirectoryMethod · 0.80
renameMethod · 0.80
isEmptyMethod · 0.45
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected