grive2 icon indicating copy to clipboard operation
grive2 copied to clipboard

[PATCH] Include symlinks to sync

Open SchweinDeBurg opened this issue 6 years ago • 0 comments

diff --git a/libgrive/src/util/OS.cc b/libgrive/src/util/OS.cc
index e8b468f..cbb528e 100644
--- a/libgrive/src/util/OS.cc
+++ b/libgrive/src/util/OS.cc
@@ -33,6 +33,8 @@

 // OS specific headers
 #include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/types.h>
@@ -56,7 +58,30 @@ void Stat( const std::string& filename, DateTime *t, off64_t *size, FileType *ft
                                << boost::errinfo_file_name(filename)
                ) ;
        }
-       
+
+       if ( S_ISLNK( s.st_mode ) )
+       {
+               std::vector<std::string::value_type> targetname( PATH_MAX ) ;
+               if ( ::realpath( filename.c_str(), targetname.data() ) == NULL )
+               {
+                       BOOST_THROW_EXCEPTION(
+                               Error()
+                                       << boost::errinfo_api_function("realpath")
+                                       << boost::errinfo_errno(errno)
+                                       << boost::errinfo_file_name(filename)
+                       ) ;
+               }
+               if ( ::stat( targetname.data(), &s ) != 0 )
+               {
+                       BOOST_THROW_EXCEPTION(
+                               Error()
+                                       << boost::errinfo_api_function("stat")
+                                       << boost::errinfo_errno(errno)
+                                       << boost::errinfo_file_name(targetname.data())
+                       ) ;
+               }
+       }
+
        if ( t )
        {
 #if defined __APPLE__ && defined __DARWIN_64_BIT_INO_T

SchweinDeBurg avatar Dec 12 '18 11:12 SchweinDeBurg