diff mbox

[11/18] btrfs restore: print progress marks for big files

Message ID 1418244708-7087-12-git-send-email-mwilck@arcor.de (mailing list archive)
State New, archived
Headers show

Commit Message

mwilck@arcor.de Dec. 10, 2014, 8:51 p.m. UTC
From: Martin Wilck <mwilck@arcor.de>

print a '+' for every 64k restored. This gives people more confidence
in long-running restore processes.

Signed-off-by: Martin Wilck <mwilck@arcor.de>
---
 cmds-restore.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/cmds-restore.c b/cmds-restore.c
index f1c63ed..004c82e 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -658,6 +658,8 @@  static int copy_file(struct btrfs_root *root, int fd, struct btrfs_key *key,
 	int loops = 0;
 	u64 bytes_written, next_pos = 0ULL;
 	u64 total_written = 0ULL;
+#define MAYBE_NL (verbose && (next_pos >> display_shift) ? "\n" : "")
+	const u64 display_shift = 16;
 	struct stat st;
 
 	path = btrfs_alloc_path();
@@ -751,6 +753,10 @@  static int copy_file(struct btrfs_root *root, int fd, struct btrfs_key *key,
 			printf("Weird extent type %d\n", extent_type);
 		}
 		total_written += bytes_written;
+		if (verbose && 
+		    ((next_pos +  bytes_written) >> display_shift) > 
+		    (next_pos >> display_shift))
+			fprintf(stderr, "+");
 		next_pos = found_key.offset + bytes_written;
 		if (ret) {
 			fprintf(stderr, "ERROR after writing %llu bytes\n",
@@ -764,6 +770,8 @@  next:
 
 set_size:
 	btrfs_free_path(path);
+
+	printf(MAYBE_NL);
 	if (get_xattrs) {
 		ret = set_file_xattrs(root, key->objectid, fd, file);
 		if (ret)