Skip to content

Commit

Permalink
windows fix caused error on unix systems, this should fix both
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelkiessling committed Feb 11, 2012
1 parent cb7dda5 commit c92a00d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions code/application/requestHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ function upload(response, request) {
console.log("about to parse");
form.parse(request, function(error, fields, files) {
console.log("parsing done");

/*
* Some systems [Windows] raise an error when you attempt to rename new file into one that already exists.
* This call deletes the previous .PNG image prior to renaming the new one in its place.
*/
fs.unlinkSync("/tmp/test.png");
fs.renameSync(files.upload.path, "/tmp/test.png");

/* Possible error on Windows systems:
tried to rename to an already existing file */
fs.rename(files.upload.path, "/tmp/test.png", function(err) {
if (err) {
fs.unlink("/tmp/test.png");
fs.rename(files.upload.path, "/tmp/test.png");
}
});
response.writeHead(200, {"Content-Type": "text/html"});
response.write("received image:<br/>");
response.write("<img src='/show' />");
Expand Down

0 comments on commit c92a00d

Please sign in to comment.