projects
/
cumulus.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
25dc252
)
Ensure filesize written to metadata log matches number of bytes dumped.
author
Michael Vrable
<mvrable@cs.ucsd.edu>
Mon, 14 May 2007 20:30:54 +0000
(13:30 -0700)
committer
Michael Vrable
<mvrable@turin.ucsd.edu>
Mon, 14 May 2007 20:30:54 +0000
(13:30 -0700)
scandir.cc
patch
|
blob
|
history
diff --git
a/scandir.cc
b/scandir.cc
index
0990bda
..
a227bb3
100644
(file)
--- a/
scandir.cc
+++ b/
scandir.cc
@@
-100,8
+100,9
@@
size_t file_read(int fd, char *buf, size_t maxlen)
}
/* Read the contents of a file (specified by an open file descriptor) and copy
}
/* Read the contents of a file (specified by an open file descriptor) and copy
- * the data to the store. */
-void dumpfile(int fd, dictionary &file_info)
+ * the data to the store. Returns the size of the file (number of bytes
+ * dumped), or -1 on error. */
+int64_t dumpfile(int fd, dictionary &file_info)
{
struct stat stat_buf;
fstat(fd, &stat_buf);
{
struct stat stat_buf;
fstat(fd, &stat_buf);
@@
-110,7
+111,7
@@
void dumpfile(int fd, dictionary &file_info)
if ((stat_buf.st_mode & S_IFMT) != S_IFREG) {
fprintf(stderr, "file is no longer a regular file!\n");
if ((stat_buf.st_mode & S_IFMT) != S_IFREG) {
fprintf(stderr, "file is no longer a regular file!\n");
- return;
+ return
-1
;
}
/* The index data consists of a sequence of pointers to the data blocks
}
/* The index data consists of a sequence of pointers to the data blocks
@@
-166,6
+167,8
@@
void dumpfile(int fd, dictionary &file_info)
segment_list.insert(i->get_ref().get_segment());
delete i;
}
segment_list.insert(i->get_ref().get_segment());
delete i;
}
+
+ return size;
}
void scanfile(const string& path)
}
void scanfile(const string& path)
@@
-175,6
+178,7
@@
void scanfile(const string& path)
struct stat stat_buf;
char *buf;
ssize_t len;
struct stat stat_buf;
char *buf;
ssize_t len;
+ int64_t file_size;
list<string> refs;
// Set to true if the item is a directory and we should recursively scan
list<string> refs;
// Set to true if the item is a directory and we should recursively scan
@@
-258,10
+262,18
@@
void scanfile(const string& path)
flags = fcntl(fd, F_GETFL);
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
flags = fcntl(fd, F_GETFL);
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
- file_
info["size"] = encode_int(stat_buf.st_size
);
-
dumpfile(fd, file_info
);
+ file_
size = dumpfile(fd, file_info
);
+
file_info["size"] = encode_int(file_size
);
close(fd);
close(fd);
+ if (file_size < 0)
+ return; // error occurred; do not dump file
+
+ if (file_size != stat_buf.st_size) {
+ fprintf(stderr, "Warning: Size of %s changed during reading\n",
+ path.c_str());
+ }
+
break;
case S_IFDIR:
inode_type = 'd';
break;
case S_IFDIR:
inode_type = 'd';