]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/network/serv_network.c
Changed serv_network.c receive_spool to remove the use of mv.
[citadel.git] / citadel / modules / network / serv_network.c
index 7a7e54f584731a0d10f801ac45c5e69672f0b9c6..4208952d30f870076507d1604db6be861c5140b1 100644 (file)
@@ -1666,8 +1666,9 @@ void receive_spool(int sock, char *remote_nodename) {
        char buf[SIZ];
        static char pbuf[IGNET_PACKET_SIZE];
        char tempfilename[PATH_MAX];
+       char filename[PATH_MAX];
        long plen;
-       FILE *fp;
+       FILE *fp, *newfp;
 
        CtdlMakeTempFileName(tempfilename, sizeof tempfilename);
        if (sock_puts(sock, "NDOP") < 0) return;
@@ -1726,15 +1727,30 @@ void receive_spool(int sock, char *remote_nodename) {
                lprintf(CTDL_NOTICE, "Received %ld octets from <%s>\n",
                                download_len, remote_nodename);
        lprintf(CTDL_DEBUG, "%s\n", buf);
-       /* TODO: make move inline. forking is verry expensive. */
+       
+       /* Now copy the temp file to its permanent location.
+        * (We copy instead of link because they may be on different filesystems)
+        */
+       begin_critical_section(S_NETSPOOL);
        snprintf(buf, 
                         sizeof buf, 
-                        "mv %s %s/%s.%ld",
-                        tempfilename, 
+                        "%s/%s.%ld",
                         ctdl_netin_dir,
                         remote_nodename, 
                         (long) getpid());
-       system(buf);
+       fp = fopen(tempfilename, "r");
+       if (fp != NULL) {
+               newfp = fopen(filename, "w");
+               if (newfp != NULL) {
+                       while (fgets(buf, sizeof buf, fp) != NULL) {
+                               fprintf(newfp, "%s", buf);
+                       }
+                       fclose(newfp);
+                       fclose(fp);
+               }
+       }
+       end_critical_section(S_NETSPOOL);
+       unlink(tempfilename);
 }