Browse Source

Save config file with correct permissions, KIKIMR-14173

ref:cf8b743a80717d0bdce9abbd1e7acbcd348f56eb
pnv1 3 years ago
parent
commit
789b46c573
1 changed files with 8 additions and 1 deletions
  1. 8 1
      ydb/public/lib/ydb_cli/common/profile_manager.cpp

+ 8 - 1
ydb/public/lib/ydb_cli/common/profile_manager.cpp

@@ -151,7 +151,14 @@ private:
             if (!configFilePath.Parent().Exists()) {
                 configFilePath.Parent().MkDirs();
             }
-            TFileOutput resultConfigFile(configFilePath);
+            if (TFileStat(configFilePath).Mode & (S_IRGRP | S_IROTH)) {
+                int chmodResult = Chmod(configFilePath.GetPath().c_str(), S_IRUSR | S_IWUSR);
+                if (chmodResult) {
+                    Cerr << "Couldn't change permissions for the file \"" << configFilePath.GetPath() << "\"" << Endl;
+                    exit(chmodResult);
+                }
+            }
+            TFileOutput resultConfigFile(TFile(configFilePath, CreateAlways | WrOnly | AWUser | ARUser));
             resultConfigFile << YAML::Dump(Config);
         }
         catch (const std::exception& e) {