{"thread":{"id":"40","subject":"[PATCH] write_sha1_buffer","startedAt":"2005-04-16T00:50:06Z","lastAt":"2005-04-16T02:59:59Z","messageCount":3,"participants":["Morten Welinder","Linus Torvalds"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"264","messageId":"118833cc05041517502fa52a89@mail.gmail.com","threadId":"40","inReplyTo":null,"subject":"[PATCH] write_sha1_buffer","fromName":"Morten Welinder","fromEmail":"mwelinder@gmail.com","sentAt":"2005-04-16T00:50:06Z","receivedAt":"2005-04-16T00:50:06Z","isPatch":true,"sender":{"key":"mwelinder@gmail.com","avatar":null},"body":"This write will failing sooner or later when someone's disk fills up. \nThat'll leave someone with\na truncated file.\n\nSigned-off-by: Morten Welinder <mwelinder@gmail.com>\n\n\n--- read-cache.c\n+++ read-cache.c        2005-04-15 20:32:52.111187168 -0400\n@@ -276,9 +276,13 @@\n                                        \" This is bad, bad, BAD!\\a\\n\");\n                return 0;\n        }\n-       write(fd, buf, size);\n-       close(fd);\n-       return 0;\n+\n+       if (write(fd, buf, size) != size) {\n+               close(fd);\n+               return error(\"Failed to write file %s\\n\", filename);\n+       }\n+\n+       return close(fd);\n }\n"},{"id":"274","messageId":"Pine.LNX.4.58.0504151942130.7211@ppc970.osdl.org","threadId":"40","inReplyTo":"118833cc05041517502fa52a89@mail.gmail.com","subject":"Re: [PATCH] write_sha1_buffer","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-04-16T02:55:02Z","receivedAt":"2005-04-16T02:55:02Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Fri, 15 Apr 2005, Morten Welinder wrote:\n>\n> This write will failing sooner or later when someone's disk fills up. \n> That'll leave someone with a truncated file.\n\nYes. On the other hand, we could try to do this even better, ie make the \nclassic write loop that handles EAGAIN.\n\nNo POSIX filesystem is supposed to return EAGAIN, but there are tons of \n\"POSIX enough\" filesystems. Notably NFS when mounted with \"intr\" (which \nsome people think is wrong, but it tends to be better than the \nalternatives if your network is flaky enough).\n\nBut yes, even just a \"write failed\" is good enough, except you should also \nmake sure that you remove the corrupt file. Sure, fsck will catch it, but \nif you don't do an fsck, somebody else might decide not to write the file \nout simply because \"it's already there\".\n\n(This is also why we should write to a temp-file and then do an atomic\n\"rename()\").\n\n\t\tLinus\n"},{"id":"275","messageId":"Pine.LNX.4.58.0504151958000.7211@ppc970.osdl.org","threadId":"40","inReplyTo":"Pine.LNX.4.58.0504151942130.7211@ppc970.osdl.org","subject":"Re: [PATCH] write_sha1_buffer","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-04-16T02:59:59Z","receivedAt":"2005-04-16T02:59:59Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Fri, 15 Apr 2005, Linus Torvalds wrote:\n> \n> (This is also why we should write to a temp-file and then do an atomic\n> \"rename()\").\n\nBtw, before anybody asks: I do _not_ think that we should do fsync() etc. \nWe don't actually destroy any old state when we write a new object, so \neven if the machine does go down, we really should just do an fsck and \nthen re-try the operation. \n\nAnal people (or people with machines that crash) can add it later if they \nreally want.\n\n\t\tLinus\n"}]}