[libglnx] fdio: glnx_file_copy_at: If no stbuf passed, do stat internally



commit 90390949f209b373f970888d1b370c2fcba0c092
Author: Colin Walters <walters verbum org>
Date:   Mon Apr 20 22:10:07 2015 -0400

    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.

 glnx-fdio.c |   12 ++++++++++++
 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,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]