sreejasahithi commented on code in PR #9735:
URL: https://github.com/apache/ozone/pull/9735#discussion_r2783651813


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/ServerUtils.java:
##########
@@ -254,6 +254,45 @@ public static String getPermissions(String key, 
ConfigurationSource conf) {
         "Invalid configuration value for key: " + key);
   }
 
+  /**
+   * Sets directory permissions based on configuration.
+   *
+   * @param dir The directory to set permissions on
+   * @param conf Configuration source
+   * @param permissionConfigKey The configuration key for permissions
+   * @throws RuntimeException If setting permissions fails
+   */
+  public static void setDataDirectoryPermissions(File dir, ConfigurationSource 
conf,
+      String permissionConfigKey) {
+    if (dir == null || !dir.exists()) {
+      return;
+    }
+    // Don't attempt to set permissions on non-writable directories
+    // This allows volume initialization to fail naturally for read-only 
volumes
+    if (!dir.canWrite()) {
+      LOG.debug("Skipping permission setting for non-writable directory {}", 
dir);
+      return;
+    }
+
+    try {
+      String permissionValue = conf.get(permissionConfigKey);
+      if (permissionValue == null) {
+        LOG.warn("Permission configuration key {} not found, skipping 
permission " +
+            "setting for directory {}", permissionConfigKey, dir);
+        return;
+      }
+      String symbolicPermission = getSymbolicPermission(permissionValue);
+      Path path = dir.toPath();
+      Files.setPosixFilePermissions(path,
+          PosixFilePermissions.fromString(symbolicPermission));
+      LOG.debug("Set permissions {} on directory {}", symbolicPermission, dir);

Review Comment:
   ```suggestion
         LOG.debug("Set permissions {} on directory {} using config key {}", 
                symbolicPermission, dir, permissionConfigKey);
   ```



##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/ServerUtils.java:
##########
@@ -254,6 +254,45 @@ public static String getPermissions(String key, 
ConfigurationSource conf) {
         "Invalid configuration value for key: " + key);
   }
 
+  /**
+   * Sets directory permissions based on configuration.
+   *
+   * @param dir The directory to set permissions on
+   * @param conf Configuration source
+   * @param permissionConfigKey The configuration key for permissions
+   * @throws RuntimeException If setting permissions fails

Review Comment:
   This method does not throw exception as we are logging the warning.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to