From 125f5b846c25f3ecef73233364e13880e25f286b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 29 Jun 2009 09:13:33 +0000 Subject: [PATCH] The copy_attributes() loop made one iteration too much trying to read and write 0 bytes after doing a successful copy of an attribute. Since fs_write_attr() was actually ignoring the position argument, this would just clobber attributes and truncate them back to 0 bytes. This was fixed in the previous commit, however, it should be noted that if the buffer which copy_attributes() uses were too small, writing attributes which live in the "small data section" iteratively would not work because of a current BFS limitation. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31310 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/bin/coreutils/src/copy.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/bin/coreutils/src/copy.c b/src/bin/coreutils/src/copy.c index 0182949a46..a80e493091 100644 --- a/src/bin/coreutils/src/copy.c +++ b/src/bin/coreutils/src/copy.c @@ -153,21 +153,28 @@ copy_attributes(int fromFd, int toFd) if (fs_stat_attr(fromFd, dirent->d_name, &info) != 0) continue; - while (info.size >= 0) { + while (true) { ssize_t bytesRead, bytesWritten; bytesRead = fs_read_attr(fromFd, dirent->d_name, info.type, pos, buffer, sizeof(buffer)); - if (bytesRead < 0) + if (bytesRead < 0) { + fprintf(stderr, "error reading attribute '%s'", dirent->d_name); break; + } bytesWritten = fs_write_attr(toFd, dirent->d_name, info.type, pos, buffer, bytesRead); - if (bytesWritten != bytesRead || bytesRead == 0) + if (bytesWritten != bytesRead) { + fprintf(stderr, "error writing attribute '%s'", dirent->d_name); break; + } pos += bytesWritten; info.size -= bytesWritten; + + if (info.size <= 0) + break; } }