Skip to content

Commit

Permalink
[VFS-405] Get/set the file permissions.
Browse files Browse the repository at this point in the history
[VFS-415] Update VFS requirement to Java 1.6.


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/vfs/trunk@1362045 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
garydgregory committed Jul 16, 2012
1 parent ac6ec91 commit 3b73cc3
Show file tree
Hide file tree
Showing 16 changed files with 1,153 additions and 105 deletions.
42 changes: 42 additions & 0 deletions core/src/main/java/org/apache/commons/vfs2/FileObject.java
Expand Up @@ -192,6 +192,48 @@ public interface FileObject extends Comparable<FileObject>, Iterable<FileObject>
FileObject resolveFile(String name, NameScope scope)
throws FileSystemException;

/**
* Sets the owner's (or everybody's) write permission
*
* @param executable
* True to allow read access, false to disallow
* @param ownerOnly
* If <code>true</code>, the permission applies only to the owner; otherwise, it applies to everybody.
* @return true if the operation succeeded
* @throws FileSystemException
* On error determining if this file exists.
* @since 2.1
*/
boolean setExecutable(boolean executable, boolean ownerOnly) throws FileSystemException;

/**
* Sets the owner's (or everybody's) read permission
*
* @param readable
* True to allow read access, false to disallow
* @param ownerOnly
* If <code>true</code>, the permission applies only to the owner; otherwise, it applies to everybody.
* @return true if the operation succeeded
* @throws FileSystemException
* On error determining if this file exists.
* @since 2.1
*/
boolean setReadable(boolean readable, boolean ownerOnly) throws FileSystemException;

/**
* Sets the owner's (or everybody's) write permission
*
* @param writable
* True to allow read access, false to disallow
* @param ownerOnly
* If <code>true</code>, the permission applies only to the owner; otherwise, it applies to everybody.
* @return true if the operation succeeded
* @throws FileSystemException
* On error determining if this file exists.
* @since 2.1
*/
boolean setWritable(boolean writable, boolean ownerOnly) throws FileSystemException;

/**
* Finds a file, relative to this file. Equivalent to calling
* <code>resolveFile( path, NameScope.FILE_SYSTEM )</code>.
Expand Down
Expand Up @@ -57,6 +57,9 @@ vfs.provider/check-is-executable.error=Could not determine if file "{0}" is exec
vfs.provider/check-is-hidden.error=Could not determine if file "{0}" is hidden.
vfs.provider/check-is-writeable.error=Could not determine if file "{0}" is writeable.
vfs.provider/check-is-readable.error=Could not determine if file "{0}" is readable.
vfs.provider/set-executable.error=Could not set the executable flag of file "{0}".
vfs.provider/set-writeable.error=Could not set the writeable flag of file "{0}".
vfs.provider/set-readable.error=Could not set the readable flag of file "{0}".
vfs.provider/get-url.error=Could not create URL for "{0}".
vfs.provider/resync.error=Could not resync "{0}".
vfs.provider/close.error=Could not close "{0}".
Expand Down
Expand Up @@ -156,6 +156,27 @@ public boolean isWriteable() throws FileSystemException
return super.isWriteable();
}

@Override
public boolean setExecutable(boolean executable, boolean ownerOnly) throws FileSystemException
{
refresh();
return super.setExecutable(executable, ownerOnly);
}

@Override
public boolean setReadable(boolean readable, boolean ownerOnly) throws FileSystemException
{
refresh();
return super.setReadable(readable, ownerOnly);
}

@Override
public boolean setWritable(boolean writable, boolean ownerOnly) throws FileSystemException
{
refresh();
return super.setWritable(writable, ownerOnly);
}

@Override
public void moveTo(FileObject destFile) throws FileSystemException
{
Expand Down
Expand Up @@ -159,11 +159,29 @@ public boolean isReadable() throws FileSystemException
return decoratedFileObject.isReadable();
}

@Override
public boolean setReadable(boolean readable, boolean ownerOnly) throws FileSystemException
{
return decoratedFileObject.setReadable(readable, ownerOnly);
}

public boolean isWriteable() throws FileSystemException
{
return decoratedFileObject.isWriteable();
}

@Override
public boolean setWritable(boolean writable, boolean ownerOnly) throws FileSystemException
{
return decoratedFileObject.setWritable(writable, ownerOnly);
}

@Override
public boolean setExecutable(boolean executable, boolean ownerOnly) throws FileSystemException
{
return decoratedFileObject.setExecutable(executable, ownerOnly);
}

public Iterator<FileObject> iterator()
{
return decoratedFileObject.iterator();
Expand Down
Expand Up @@ -180,6 +180,38 @@ public boolean isWriteable() throws FileSystemException
}
}

@Override
public boolean isExecutable() throws FileSystemException
{
synchronized (this) {
return super.isExecutable();
}
}

@Override
public boolean setReadable(boolean readable, boolean ownerOnly) throws FileSystemException
{
synchronized (this) {
return super.setReadable(readable, ownerOnly);
}
}

@Override
public boolean setWritable(boolean writable, boolean ownerOnly) throws FileSystemException
{
synchronized (this) {
return super.setWritable(writable, ownerOnly);
}
}

@Override
public boolean setExecutable(boolean executable, boolean ownerOnly) throws FileSystemException
{
synchronized (this) {
return super.setExecutable(executable, ownerOnly);
}
}

@Override
public void moveTo(FileObject destFile) throws FileSystemException
{
Expand Down
Expand Up @@ -175,6 +175,17 @@ protected boolean doIsReadable() throws Exception
return true;
}

/**
* Only called if {@link #doGetType} does not return {@link FileType#IMAGINARY}.
*
* @see {@link #setReadable(boolean, boolean)}
* @since 2.1
*/
protected boolean doSetReadable(boolean readable, boolean ownerOnly) throws Exception
{
return false;
}

/**
* Determines if this file can be written to. Is only called if
* {@link #doGetType} does not return {@link FileType#IMAGINARY}.
Expand All @@ -188,6 +199,28 @@ protected boolean doIsWriteable() throws Exception
return true;
}

/**
* Only called if {@link #doGetType} does not return {@link FileType#IMAGINARY}.
*
* @see {@link #setWritable(boolean, boolean)}
* @since 2.1
*/
protected boolean doSetWritable(boolean writable, boolean ownerOnly) throws Exception
{
return false;
}

/**
* Only called if {@link #doGetType} does not return {@link FileType#IMAGINARY}.
*
* @see {@link #setExecutable(boolean, boolean)}
* @since 2.1
*/
protected boolean doSetExecutable(boolean writable, boolean ownerOnly) throws Exception
{
return false;
}

/**
* Lists the children of this file. Is only called if {@link #doGetType}
* returns {@link FileType#FOLDER}. The return value of this method
Expand Down Expand Up @@ -620,6 +653,26 @@ public boolean isReadable() throws FileSystemException
}
}

@Override
public boolean setReadable(boolean readable, boolean ownerOnly) throws FileSystemException
{
try
{
if (exists())
{
return doSetReadable(readable, ownerOnly);
}
else
{
return false;
}
}
catch (final Exception exc)
{
throw new FileSystemException("vfs.provider/set-readable.error", name, exc);
}
}

/**
* Determines if this file can be written to.
* @return true if the file can be written to, false otherwise.
Expand Down Expand Up @@ -649,6 +702,46 @@ public boolean isWriteable() throws FileSystemException
}
}

@Override
public boolean setWritable(boolean readable, boolean ownerOnly) throws FileSystemException
{
try
{
if (exists())
{
return doSetWritable(readable, ownerOnly);
}
else
{
return false;
}
}
catch (final Exception exc)
{
throw new FileSystemException("vfs.provider/set-writeable.error", name, exc);
}
}

@Override
public boolean setExecutable(boolean readable, boolean ownerOnly) throws FileSystemException
{
try
{
if (exists())
{
return doSetExecutable(readable, ownerOnly);
}
else
{
return false;
}
}
catch (final Exception exc)
{
throw new FileSystemException("vfs.provider/set-executable.error", name, exc);
}
}

/**
* Returns an iterator over a set of all FileObject in this file object.
*
Expand Down
Expand Up @@ -161,6 +161,12 @@ protected boolean doIsWriteable() throws FileSystemException
return file.canWrite();
}

@Override
protected boolean doSetWritable(boolean writable, boolean ownerOnly) throws Exception
{
return file.setWritable(writable, ownerOnly);
}

/**
* Determines if this file is hidden.
*/
Expand Down Expand Up @@ -188,6 +194,18 @@ protected boolean doIsReadable() throws FileSystemException
return file.canRead();
}

@Override
protected boolean doSetReadable(boolean readable, boolean ownerOnly) throws Exception
{
return file.setReadable(readable, ownerOnly);
}

@Override
protected boolean doSetExecutable(boolean executable, boolean ownerOnly) throws Exception
{
return file.setExecutable(executable, ownerOnly);
}

/**
* Gets the last modified time of this file.
*/
Expand Down

0 comments on commit 3b73cc3

Please sign in to comment.