]> code.citadel.org Git - citadel.git/blobdiff - citadel/file_ops.c
* partialy revert r8246; we're working in units of one here, so the number of units...
[citadel.git] / citadel / file_ops.c
index 8fcc068bfd88bf2e1a555c839a6e9de920995603..ced5a31d568c3fef6f83466c7e51313abfdd4fbc 100644 (file)
@@ -163,6 +163,7 @@ void cmd_movf(char *cmdbuf)
        char buf[PATH_MAX];
        int a;
        struct ctdlroom qrbuf;
+       int rv = 0;
 
        extract_token(filename, cmdbuf, 0, '|', sizeof filename);
        extract_token(newroom, cmdbuf, 1, '|', sizeof newroom);
@@ -194,7 +195,7 @@ void cmd_movf(char *cmdbuf)
                return;
        }
 
-       if (getroom(&qrbuf, newroom) != 0) {
+       if (CtdlGetRoom(&qrbuf, newroom) != 0) {
                cprintf("%d '%s' does not exist.\n", ERROR + ROOM_NOT_FOUND, newroom);
                return;
        }
@@ -216,7 +217,7 @@ void cmd_movf(char *cmdbuf)
        snprintf(buf, sizeof buf,
                 "cat ./files/%s/filedir |grep \"%s\" >>./files/%s/filedir",
                 CC->room.QRdirname, filename, qrbuf.QRdirname);
-       system(buf);
+       rv = system(buf);
        cprintf("%d File '%s' has been moved.\n", CIT_OK, filename);
 }
 
@@ -307,6 +308,7 @@ void cmd_oimg(char *cmdbuf)
        char which_user[USERNAME_SIZE];
        int which_floor;
        int a;
+       int rv;
 
        extract_token(filename, cmdbuf, 0, '|', sizeof filename);
 
@@ -324,7 +326,7 @@ void cmd_oimg(char *cmdbuf)
 
        if (!strcasecmp(filename, "_userpic_")) {
                extract_token(which_user, cmdbuf, 1, '|', sizeof which_user);
-               if (getuser(&usbuf, which_user) != 0) {
+               if (CtdlGetUser(&usbuf, which_user) != 0) {
                        cprintf("%d No such user.\n",
                                ERROR + NO_SUCH_USER);
                        return;
@@ -363,7 +365,7 @@ void cmd_oimg(char *cmdbuf)
                        ERROR + FILE_NOT_FOUND, pathname, strerror(errno));
                return;
        }
-       fread(&MimeTestBuf[0], 1, 32, CC->download_fp);
+       rv = fread(&MimeTestBuf[0], 1, 32, CC->download_fp);
        rewind (CC->download_fp);
        OpenCmdResult(pathname, GuessMimeType(&MimeTestBuf[0], 32));
 }
@@ -547,7 +549,7 @@ void cmd_clos(char *cmdbuf)
 /*
  * abort an upload
  */
-void abort_upl(struct CitContext *who)
+void abort_upl(CitContext *who)
 {
        if (who->upload_fp != NULL) {
                fclose(who->upload_fp);
@@ -635,9 +637,15 @@ void cmd_read(char *cmdbuf)
        buf = malloc(bytes + 1);
 
        fseek(CC->download_fp, start_pos, 0);
+
        actual_bytes = fread(buf, 1, bytes, CC->download_fp);
-       cprintf("%d %d\n", BINARY_FOLLOWS, (int)actual_bytes);
-       client_write(buf, actual_bytes);
+       if (actual_bytes > 0) {
+               cprintf("%d %d\n", BINARY_FOLLOWS, (int)actual_bytes);
+               client_write(buf, bytes);
+       }
+       else {
+               cprintf("%d %s\n", ERROR, strerror(errno));
+       }
        free(buf);
 }
 
@@ -650,6 +658,7 @@ void cmd_writ(char *cmdbuf)
 {
        int bytes;
        char *buf;
+       int rv;
 
        unbuffer_output();
 
@@ -669,7 +678,7 @@ void cmd_writ(char *cmdbuf)
        cprintf("%d %d\n", SEND_BINARY, bytes);
        buf = malloc(bytes + 1);
        client_read(buf, bytes);
-       fwrite(buf, bytes, 1, CC->upload_fp);
+       rv = fwrite(buf, bytes, 1, CC->upload_fp);
        free(buf);
 }
 
@@ -779,18 +788,20 @@ void cmd_nuop(char *cmdbuf)
 
 CTDL_MODULE_INIT(file_ops)
 {
-       CtdlRegisterProtoHook(cmd_delf, "DELF", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_movf, "MOVF", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_open, "OPEN", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_clos, "CLOS", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_uopn, "UOPN", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_ucls, "UCLS", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_read, "READ", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_writ, "WRIT", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_oimg, "OIMG", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_ndop, "NDOP", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_nuop, "NUOP", "Autoconverted. TODO: document me.");
-       CtdlRegisterProtoHook(cmd_uimg, "UIMG", "Autoconverted. TODO: document me.");
+       if (!threading) {
+               CtdlRegisterProtoHook(cmd_delf, "DELF", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_movf, "MOVF", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_open, "OPEN", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_clos, "CLOS", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_uopn, "UOPN", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_ucls, "UCLS", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_read, "READ", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_writ, "WRIT", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_oimg, "OIMG", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_ndop, "NDOP", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_nuop, "NUOP", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_uimg, "UIMG", "Autoconverted. TODO: document me.");
+       }
         /* return our Subversion id for the Log */
        return "$Id$";
 }