Skip to content

Commit

Permalink
fs-posix: Implement fs_stat() with fstat() if fd is already open.
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Mar 9, 2015
1 parent b82a8dd commit 664bf3e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib-fs/fs-posix.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit 664bf3e

Please sign in to comment.