Browse Source

better handle incomplete reads/writes in copying files

pull/403/head
Antonio SJ Musumeci 8 years ago
parent
commit
ccaa458739
  1. 19
      src/fs_clonefile.cpp

19
src/fs_clonefile.cpp

@ -57,19 +57,18 @@ writen(const int fd,
ssize_t nwritten; ssize_t nwritten;
nleft = count; nleft = count;
while(nleft > 0)
do
{ {
nwritten = fs::write(fd,buf,nleft); nwritten = fs::write(fd,buf,nleft);
if(nwritten == -1)
{
if(errno == EINTR)
if((nwritten == -1) && (errno == EINTR))
continue; continue;
if(nwritten == -1)
return -1; return -1;
}
nleft -= nwritten; nleft -= nwritten;
buf += nwritten; buf += nwritten;
} }
while(nleft > 0);
return count; return count;
} }
@ -96,12 +95,12 @@ copyfile_rw(const int fdin,
while(totalwritten < count) while(totalwritten < count)
{ {
nr = fs::read(fdin,&buf[0],bufsize); nr = fs::read(fdin,&buf[0],bufsize);
if(nr == -1)
{
if(errno == EINTR)
if(nr == 0)
return totalwritten;
if((nr == -1) && (errno == EINTR))
continue; continue;
if(nr == -1)
return -1; return -1;
}
nw = writen(fdout,&buf[0],nr); nw = writen(fdout,&buf[0],nr);
if(nw == -1) if(nw == -1)
@ -110,7 +109,7 @@ copyfile_rw(const int fdin,
totalwritten += nw; totalwritten += nw;
} }
return count;
return totalwritten;
} }
static static

Loading…
Cancel
Save