brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Move to java7 setPosixFilePermiss...
Date Tue, 15 Sep 2015 10:03:11 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/896#discussion_r39493486
  
    --- Diff: utils/common/src/main/java/org/apache/brooklyn/util/io/FileUtil.java ---
    @@ -73,36 +77,11 @@ public static void setFilePermissionsTo700(File file) throws IOException
{
             }
         }
         
    -    // When we move to java 7, we can use Files.setPosixFilePermissions
    +    private static final Set<PosixFilePermission> posixPermissions600 = PosixFilePermissions.fromString("rw-------");
    +    
         public static void setFilePermissionsTo600(File file) throws IOException {
             file.createNewFile();
    -        file.setExecutable(false, false);
    -        file.setReadable(false, false);
    -        file.setWritable(false, false);
    -        file.setReadable(true, true);
    -        file.setWritable(true, true);
    -        
    -        boolean setRead = file.setReadable(false, false) & file.setReadable(true,
true);
    -        boolean setWrite = file.setWritable(false, false) & file.setWritable(true,
true);
    -        boolean setExec = file.setExecutable(false, false);
    -        
    -        if (setRead && setWrite && setExec) {
    -            if (LOG.isTraceEnabled()) LOG.trace("Set permissions to 600 for file {}",
file.getAbsolutePath());
    -        } else {
    --- End diff --
    
    The previous code relied on `file.setReadable` returning false, so as to do a single `LOG.warn`
if the file was not accessible. I presume that `Files.setPosixFilePermissions` will throw
an `IOException`.
    
    I worry about us propagating the exception, without changing the callers. For example,
see `FileBasedStoreObjectAccessor.put`. This will now fail, rather than just writing to the
file without changing the file permission. We'd definitely want the warn (done just once,
rather than many times a second!) in such a situation.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message