Hello, Here a small improvement for R. When you use the function write.table, if the disk is full for example, the function doesn't return an error and the file is written but truncated. It can be a source of mistakes because you can then copy the output file and think everything is ok. How to reproduce ------------------------->> write.csv(1:10000000, 'path')You must have a path with a small amount of disk available (on linux: http://souptonuts.sourceforge.net/quota_tutorial.html) I have joined the patch in this email. Can you open a bugzilla account for me to keep track of this change. Thanks, Jean-S?bastien Bevilacqua -------------- next part -------------- Index: src/library/utils/src/io.c ==================================================================--- src/library/utils/src/io.c (r?vision 72357) +++ src/library/utils/src/io.c (copie de travail) @@ -1120,12 +1120,23 @@ for(int i = 0; i < nr; i++) { if(i % 1000 == 999) R_CheckUserInterrupt(); if(!isNull(rnames)) - Rconn_printf(con, "%s%s", - EncodeElement2(rnames, i, quote_rn, qmethod, - &strBuf, sdec), csep); + + if(Rconn_printf(con, "%s%s", EncodeElement2(rnames, i, quote_rn, qmethod, &strBuf, sdec), csep) < 0) { + error(_("IO error, cannot write table.")); + break; + } + for(int j = 0; j < nc; j++) { xj = VECTOR_ELT(x, j); - if(j > 0) Rconn_printf(con, "%s", csep); + + if(j > 0) { + if(Rconn_printf(con, "%s", csep) < 0) { + error(_("IO error, cannot write table.")); + i = nr; + break; + } + } + if(isna(xj, i)) tmp = cna; else { if(!isNull(levels[j])) { @@ -1148,9 +1159,17 @@ &strBuf, sdec); } } - Rconn_printf(con, "%s", tmp); + + if(Rconn_printf(con, "%s", tmp) < 0) { + error(_("IO error, cannot write table.")); + i = nr; + break; + } } - Rconn_printf(con, "%s", ceol); + if(Rconn_printf(con, "%s", ceol) < 0) { + error(_("IO error, cannot write table.")); + break; + } } } else { /* A matrix */ @@ -1163,20 +1182,36 @@ for(int i = 0; i < nr; i++) { if(i % 1000 == 999) R_CheckUserInterrupt(); - if(!isNull(rnames)) - Rconn_printf(con, "%s%s", - EncodeElement2(rnames, i, quote_rn, qmethod, - &strBuf, sdec), csep); + if(!isNull(rnames)) { + if(Rconn_printf(con, "%s%s", EncodeElement2(rnames, i, quote_rn, qmethod, &strBuf, sdec), csep) < 0) { + error(_("IO error, cannot write table.")); + break; + } + } for(int j = 0; j < nc; j++) { - if(j > 0) Rconn_printf(con, "%s", csep); + if(j > 0) { + if(Rconn_printf(con, "%s", csep) < 0) { + error(_("IO error, cannot write table.")); + i = nr; + break; + } + } if(isna(x, i + j*nr)) tmp = cna; else { tmp = EncodeElement2(x, i + j*nr, quote_col[j], qmethod, &strBuf, sdec); } - Rconn_printf(con, "%s", tmp); + if(Rconn_printf(con, "%s", tmp) < 0) { + error(_("IO error, cannot write table.")); + i = nr; + break; + } } - Rconn_printf(con, "%s", ceol); + + if(Rconn_printf(con, "%s", ceol) < 0) { + error(_("IO error, cannot write table.")); + break; + } } }
Hello, I have sent a mail but I got no answer. Can you create a bugzilla account for me. Thanks, Jean-S?bastien Bevilacqua 2017-03-20 10:24 GMT+01:00 realitix <realitix at gmail.com>:> Hello, > Here a small improvement for R. > > When you use the function write.table, if the disk is full for example, > the function doesn't return an error and the file is written but truncated. > > It can be a source of mistakes because you can then copy the output file > and think everything is ok. > > How to reproduce > ------------------------- > > >> write.csv(1:10000000, 'path') > > You must have a path with a small amount of disk available (on linux: > http://souptonuts.sourceforge.net/quota_tutorial.html) > > I have joined the patch in this email. > Can you open a bugzilla account for me to keep track of this change. > > Thanks, > Jean-S?bastien Bevilacqua >[[alternative HTML version deleted]]
>>>>> realitix <realitix at gmail.com> >>>>> on Wed, 22 Mar 2017 10:17:54 +0100 writes:> Hello, > I have sent a mail but I got no answer. All work here happens on a volunteer basis... and it seems everybody was busy or not interested. > Can you create a bugzilla account for me. I've done that now. Note that your prposed patch did contain a bit too many "copy & paste" repetitions... which I personally would have liked to be written differently, using a wrapper (function or macro). Also, let's assume on Linux, would there be a way to create a small, say 1 MB, temporary file system as a non-root user? In that case, we could do all the testing from inside R .. Best, Martin Maechler > Thanks, > Jean-S?bastien Bevilacqua > 2017-03-20 10:24 GMT+01:00 realitix <realitix at gmail.com>: >> Hello, >> Here a small improvement for R. >> >> When you use the function write.table, if the disk is full for example, >> the function doesn't return an error and the file is written but truncated. >> >> It can be a source of mistakes because you can then copy the output file >> and think everything is ok. >> >> How to reproduce >> ------------------------- >> >> >> write.csv(1:10000000, 'path') >> >> You must have a path with a small amount of disk available (on linux: >> http://souptonuts.sourceforge.net/quota_tutorial.html) >> >> I have joined the patch in this email. >> Can you open a bugzilla account for me to keep track of this change. >> >> Thanks, >> Jean-S?bastien Bevilacqua >> > [[alternative HTML version deleted]] > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Seemingly Similar Threads
- R Bug: write.table for matrix of more than 2, 147, 483, 648 elements
- R Bug: write.table for matrix of more than 2, 147, 483, 648 elements
- R Bug: write.table for matrix of more than 2, 147, 483, 648 elements
- R Bug: write.table for matrix of more than 2, 147, 483, 648 elements
- [New Patch] Fix disk corruption when writing