changeset 18317:2def20c622a6

fs-posix: Implement fs_stat() with fstat() if fd is already open.
author Timo Sirainen <tss@iki.fi>
date Mon, 09 Mar 2015 20:26:50 +0200
parents 5bd6e2eee650
children 4a80d3bbf14d
files src/lib-fs/fs-posix.c
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-fs/fs-posix.c	Mon Mar 09 19:29:04 2015 +0200
+++ b/src/lib-fs/fs-posix.c	Mon Mar 09 20:26:50 2015 +0200
@@ -606,9 +606,17 @@
 static int fs_posix_stat(struct fs_file *_file, struct stat *st_r)
 {
 	struct posix_fs_file *file = (struct posix_fs_file *)_file;
-	if (stat(file->full_path, st_r) < 0) {
-		fs_set_error(_file->fs, "stat(%s) failed: %m", file->full_path);
-		return -1;
+
+	if (file->fd != -1) {
+		if (fstat(file->fd, st_r) < 0) {
+			fs_set_error(_file->fs, "fstat(%s) failed: %m", file->full_path);
+			return -1;
+		}
+	} else {
+		if (stat(file->full_path, st_r) < 0) {
+			fs_set_error(_file->fs, "stat(%s) failed: %m", file->full_path);
+			return -1;
+		}
 	}
 	return 0;
 }