Added a progress monitor when copying large files (ie. over 1 MB).
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23457 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -883,14 +883,35 @@ static fssh_status_t
|
|||||||
copy_file_contents(const char *source, File *sourceFile, const char *target,
|
copy_file_contents(const char *source, File *sourceFile, const char *target,
|
||||||
File *targetFile)
|
File *targetFile)
|
||||||
{
|
{
|
||||||
|
fssh_off_t chunkSize = (sourceFile->Stat().fssh_st_size / 20) / sCopyBufferSize * sCopyBufferSize;
|
||||||
|
if (chunkSize == 0)
|
||||||
|
chunkSize = 1;
|
||||||
|
|
||||||
|
bool progress = sourceFile->Stat().fssh_st_size > 1024 * 1024;
|
||||||
|
if (progress) {
|
||||||
|
printf("%s ", strrchr(target, '/') ? strrchr(target, '/') + 1 : target);
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
fssh_off_t total = 0;
|
||||||
fssh_ssize_t bytesRead;
|
fssh_ssize_t bytesRead;
|
||||||
while ((bytesRead = sourceFile->Read(sCopyBuffer, sCopyBufferSize)) > 0) {
|
while ((bytesRead = sourceFile->Read(sCopyBuffer, sCopyBufferSize)) > 0) {
|
||||||
fssh_ssize_t bytesWritten = targetFile->Write(sCopyBuffer, bytesRead);
|
fssh_ssize_t bytesWritten = targetFile->Write(sCopyBuffer, bytesRead);
|
||||||
|
if (progress && (total % chunkSize) == 0) {
|
||||||
|
putchar('.');
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
if (bytesWritten < 0) {
|
if (bytesWritten < 0) {
|
||||||
fprintf(stderr, "Error while writing to file `%s': %s\n",
|
fprintf(stderr, "Error while writing to file `%s': %s\n",
|
||||||
target, fssh_strerror(bytesWritten));
|
target, fssh_strerror(bytesWritten));
|
||||||
return bytesWritten;
|
return bytesWritten;
|
||||||
}
|
}
|
||||||
|
if (bytesWritten != bytesRead) {
|
||||||
|
fprintf(stderr, "Could not write all data to file \"%s\".\n",
|
||||||
|
target);
|
||||||
|
return FSSH_B_IO_ERROR;
|
||||||
|
}
|
||||||
|
total += bytesWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytesRead < 0) {
|
if (bytesRead < 0) {
|
||||||
@@ -899,6 +920,9 @@ copy_file_contents(const char *source, File *sourceFile, const char *target,
|
|||||||
return bytesRead;
|
return bytesRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (progress)
|
||||||
|
putchar('\n');
|
||||||
|
|
||||||
return FSSH_B_OK;
|
return FSSH_B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user