Browse Source

Fix case when 'arc export' not set executable bit

В этом ревью сделано две вещи:
1. В util/system/fs добавилась функция SetExecutable
2. В TDataFetcher добавилась функция FetchEntry, аналог FetchBlob/FetchTree но с пробросом метаинформации
06888e7a37526ef46789eafd29bd2728661d8be7
ilikepugs 1 year ago
parent
commit
051211a92f
2 changed files with 28 additions and 2 deletions
  1. 21 2
      util/system/fs.cpp
  2. 7 0
      util/system/fs.h

+ 21 - 2
util/system/fs.cpp

@@ -8,12 +8,13 @@
     #include <errno.h>
 #endif
 
+#include <util/folder/iterator.h>
+#include <util/folder/path.h>
 #include <util/generic/yexception.h>
 #include <util/memory/tempbuf.h>
 #include <util/stream/file.h>
-#include <util/folder/iterator.h>
 #include <util/system/fstat.h>
-#include <util/folder/path.h>
+#include <util/system/sysstat.h>
 
 bool NFs::Remove(const TString& path) {
 #if defined(_win_)
@@ -23,6 +24,24 @@ bool NFs::Remove(const TString& path) {
 #endif
 }
 
+bool NFs::SetExecutable(const TString& path, bool exec) {
+#ifdef _unix_
+    TFileStat stat(path);
+    ui32 mode = stat.Mode;
+    if (exec) {
+        mode |= S_IXUSR | S_IXGRP | S_IXOTH;
+    } else {
+        mode &= ~(S_IXUSR | S_IXGRP | S_IXOTH);
+    }
+    if (stat.Mode != 0 && mode != stat.Mode) {
+        return !Chmod(path.c_str(), mode);
+    }
+#endif
+    Y_UNUSED(exec);
+    Y_UNUSED(path);
+    return true;
+}
+
 void NFs::RemoveRecursive(const TString& path) {
     static const TStringBuf errStr = "error while removing ";
 

+ 7 - 0
util/system/fs.h

@@ -23,6 +23,13 @@ namespace NFs {
 
     Y_DECLARE_FLAGS(EFilePermissions, EFilePermission);
 
+    /// Add executable bit
+    ///
+    /// @param[in] path  Path to mark as executable
+    /// @param[in] exec  New value of execution bit
+    /// @returns         true if bit has changed or false otherwise
+    bool SetExecutable(const TString& path, bool exec);
+
     /// Remove a file or empty directory
     ///
     /// @param[in] path  Path to file or directory