summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2015-04-20 22:10:07 -0400
committerColin Walters <walters@verbum.org>2015-04-20 22:10:07 -0400
commit90390949f209b373f970888d1b370c2fcba0c092 (patch)
tree847717bf04a38ac839fb95732552fa7c7ca984e6
parent381ca54ee3a47de291d26a5db8772732fb4a9d59 (diff)
downloadlibglnx-90390949f209b373f970888d1b370c2fcba0c092.tar.gz
fdio: glnx_file_copy_at: If no stbuf passed, do stat internally
There are some cases where we want to copy with just a filename, so let's be convenient in that case and do stat for the caller. This will be used by an ostree commit.
-rw-r--r--glnx-fdio.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/glnx-fdio.c b/glnx-fdio.c
index a436209..517f1e5 100644
--- a/glnx-fdio.c
+++ b/glnx-fdio.c
@@ -484,6 +484,7 @@ glnx_file_copy_at (int src_dfd,
struct timespec ts[2];
glnx_fd_close int src_fd = -1;
glnx_fd_close int dest_fd = -1;
+ struct stat local_stbuf;
if (g_cancellable_set_error_if_cancelled (cancellable, error))
goto out;
@@ -491,6 +492,17 @@ glnx_file_copy_at (int src_dfd,
src_dfd = glnx_dirfd_canonicalize (src_dfd);
dest_dfd = glnx_dirfd_canonicalize (dest_dfd);
+ /* Automatically do stat() if no stat buffer was supplied */
+ if (!src_stbuf)
+ {
+ if (fstatat (src_dfd, src_subpath, &local_stbuf, AT_SYMLINK_NOFOLLOW) != 0)
+ {
+ glnx_set_error_from_errno (error);
+ goto out;
+ }
+ src_stbuf = &local_stbuf;
+ }
+
if (S_ISLNK (src_stbuf->st_mode))
{
return copy_symlink_at (src_dfd, src_subpath, src_stbuf,