From 664bf3e236c214aee86294483c379e4fa66c2e63 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 9 Mar 2015 20:26:50 +0200 Subject: [PATCH] fs-posix: Implement fs_stat() with fstat() if fd is already open. --- src/lib-fs/fs-posix.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib-fs/fs-posix.c b/src/lib-fs/fs-posix.c index dc7c7818a3..2d0023ad03 100644 --- a/src/lib-fs/fs-posix.c +++ b/src/lib-fs/fs-posix.c @@ -606,9 +606,17 @@ static int fs_posix_exists(struct fs_file *_file) 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; }