|
From: <fd...@us...> - 2007-06-30 11:58:47
|
Revision: 3337
http://jnode.svn.sourceforge.net/jnode/?rev=3337&view=rev
Author: fduminy
Date: 2007-06-30 04:58:44 -0700 (Sat, 30 Jun 2007)
Log Message:
-----------
integration of OpenJDK: added binding with VM for new File APIs (jdk 1.6)
Modified Paths:
--------------
trunk/fs/src/fs/org/jnode/fs/FSAccessRights.java
trunk/fs/src/fs/org/jnode/fs/FSEntry.java
trunk/fs/src/fs/org/jnode/fs/FileSystem.java
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystem.java
trunk/fs/src/fs/org/jnode/fs/fat/FatBasicDirEntry.java
trunk/fs/src/fs/org/jnode/fs/fat/FatDirEntry.java
trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystem.java
trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFileSystem.java
trunk/fs/src/fs/org/jnode/fs/iso9660/ISO9660FileSystem.java
trunk/fs/src/fs/org/jnode/fs/jarfs/JarFileSystem.java
trunk/fs/src/fs/org/jnode/fs/jfat/FatEntry.java
trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystem.java
trunk/fs/src/fs/org/jnode/fs/jifs/ExtFSEntry.java
trunk/fs/src/fs/org/jnode/fs/jifs/JIFileSystem.java
trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFileSystem.java
trunk/fs/src/fs/org/jnode/fs/service/def/FileSystemAPIImpl.java
trunk/fs/src/fs/org/jnode/fs/service/def/VirtualFS.java
trunk/fs/src/fs/org/jnode/fs/smbfs/SMBFileSystem.java
trunk/fs/src/fs/org/jnode/fs/spi/AbstractFSEntry.java
Added Paths:
-----------
trunk/fs/src/fs/org/jnode/fs/spi/UnixFSAccessRights.java
Removed Paths:
-------------
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2AccessRights.java
Modified: trunk/fs/src/fs/org/jnode/fs/FSAccessRights.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/FSAccessRights.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/FSAccessRights.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -38,4 +38,15 @@
public Principal getOwner()
throws IOException;
+ public boolean canRead();
+
+ public boolean canWrite();
+
+ public boolean canExecute();
+
+ public boolean setReadable(boolean enable, boolean owneronly);
+
+ public boolean setWritable(boolean enable, boolean owneronly);
+
+ public boolean setExecutable(boolean enable, boolean owneronly);
}
Modified: trunk/fs/src/fs/org/jnode/fs/FSEntry.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/FSEntry.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/FSEntry.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -103,5 +103,5 @@
* @return true if the entry need to be saved
* @throws IOException
*/
- public boolean isDirty() throws IOException;
+ public boolean isDirty() throws IOException;
}
Modified: trunk/fs/src/fs/org/jnode/fs/FileSystem.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/FileSystem.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/FileSystem.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -59,4 +59,10 @@
* Is this filesystem closed.
*/
public boolean isClosed();
+
+ public long getTotalSpace();
+
+ public long getFreeSpace();
+
+ public long getUsableSpace();
}
Deleted: trunk/fs/src/fs/org/jnode/fs/ext2/Ext2AccessRights.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2AccessRights.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2AccessRights.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -1,55 +0,0 @@
-/*
- * $Id$
- *
- * JNode.org
- * Copyright (C) 2003-2006 JNode.org
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package org.jnode.fs.ext2;
-
-import java.security.Principal;
-
-import org.jnode.fs.FSAccessRights;
-import org.jnode.fs.FileSystem;
-
-/**
- * @author Andras Nagy
- */
-public class Ext2AccessRights implements FSAccessRights {
-
- /**
- * @see org.jnode.fs.FSAccessRights#getOwner()
- */
- public Principal getOwner() {
- return null;
- }
-
- /**
- * @see org.jnode.fs.FSObject#isValid()
- */
- public boolean isValid() {
- return false;
- }
-
- /**
- * @see org.jnode.fs.FSObject#getFileSystem()
- */
- public FileSystem getFileSystem() {
- return null;
- }
-
-}
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystem.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystem.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystem.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -986,4 +986,19 @@
protected synchronized INodeCache getInodeCache() {
return inodeCache;
}
+
+ public long getFreeSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getTotalSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getUsableSpace() {
+ // TODO implement me
+ return 0;
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/fat/FatBasicDirEntry.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/fat/FatBasicDirEntry.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/fat/FatBasicDirEntry.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -21,6 +21,10 @@
package org.jnode.fs.fat;
+import java.io.IOException;
+
+import org.jnode.fs.FSAccessRights;
+
/**
* @author gbin
*/
@@ -40,5 +44,4 @@
public void write(byte[] dest, int offset) {
System.arraycopy(rawData, 0, dest, offset, 32);
}
-
}
Modified: trunk/fs/src/fs/org/jnode/fs/fat/FatDirEntry.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/fat/FatDirEntry.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/fat/FatDirEntry.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -28,6 +28,7 @@
import org.jnode.fs.FSDirectory;
import org.jnode.fs.FSEntry;
import org.jnode.fs.FSFile;
+import org.jnode.fs.spi.UnixFSAccessRights;
import org.jnode.fs.util.DosUtils;
import org.jnode.util.LittleEndian;
import org.jnode.util.NumberUtils;
@@ -58,6 +59,9 @@
/** Directory this entry is a part of */
private final AbstractDirectory parent;
+ /** access rights of the entry */
+ private final FSAccessRights rights;
+
public static FatBasicDirEntry fatDirEntryFactory(AbstractDirectory dir, byte[] src, int offset) {
int flags = LittleEndian.getUInt8(src, offset + 0x0b);
boolean r = (flags & F_READONLY) != 0;
@@ -98,6 +102,7 @@
this.flags = F_ARCHIVE;
this.lastModified = System.currentTimeMillis();
this._dirty = false;
+ this.rights = new UnixFSAccessRights(getFileSystem());
}
/**
@@ -135,6 +140,7 @@
this.startCluster = LittleEndian.getUInt16(src, offset + 0x1a);
this.length = LittleEndian.getUInt32(src, offset + 0x1c);
this._dirty = false;
+ this.rights = new UnixFSAccessRights(getFileSystem());
}
/**
@@ -511,6 +517,7 @@
public FSDirectory getParent() {
return parent;
}
+
/**
* Gets the accessrights for this entry.
@@ -518,6 +525,6 @@
* @throws IOException
*/
public FSAccessRights getAccessRights() throws IOException {
- throw new IOException("Not implemented yet");
- }
+ return rights;
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystem.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystem.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/fat/FatFileSystem.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -196,4 +196,20 @@
// TODO Auto-generated method stub
return null;
}
+
+
+ public long getFreeSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getTotalSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getUsableSpace() {
+ // TODO implement me
+ return 0;
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFileSystem.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFileSystem.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/ftpfs/FTPFileSystem.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -153,4 +153,20 @@
public boolean isReadOnly() {
return true;
}
+
+
+ public long getFreeSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getTotalSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getUsableSpace() {
+ // TODO implement me
+ return 0;
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/iso9660/ISO9660FileSystem.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/iso9660/ISO9660FileSystem.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/iso9660/ISO9660FileSystem.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -107,4 +107,20 @@
// TODO Auto-generated method stub
return null;
}
+
+
+ public long getFreeSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getTotalSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getUsableSpace() {
+ // TODO implement me
+ return 0;
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/jarfs/JarFileSystem.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jarfs/JarFileSystem.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/jarfs/JarFileSystem.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -80,4 +80,20 @@
protected FSEntry createRootEntry() {
return rootEntry;
}
+
+
+ public long getFreeSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getTotalSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getUsableSpace() {
+ // TODO implement me
+ return 0;
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/jfat/FatEntry.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jfat/FatEntry.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/jfat/FatEntry.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -204,12 +204,16 @@
throw new UnsupportedOperationException ( "getFile" );
}
+ /**
+ * Gets the accessrights for this entry.
+ *
+ * @throws IOException
+ */
+ public FSAccessRights getAccessRights() throws IOException {
+ throw new IOException("Not implemented yet");
+ }
- public FSAccessRights getAccessRights() {
- throw new UnsupportedOperationException ( "getAccessRights" );
- }
-
public String getPath() {
StringBuilder path = new StringBuilder ( 1024 );
FatDirectory parent = (FatDirectory)getParent();
Modified: trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystem.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystem.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/jfat/FatFileSystem.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -114,4 +114,19 @@
return out.toString();
}
+
+ public long getFreeSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getTotalSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getUsableSpace() {
+ // TODO implement me
+ return 0;
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/jifs/ExtFSEntry.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jifs/ExtFSEntry.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/jifs/ExtFSEntry.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -23,13 +23,13 @@
import org.jnode.fs.FSEntry;
import org.jnode.fs.FSDirectory;
+import org.jnode.fs.spi.UnixFSAccessRights;
/**
* @author Andreas H\u00e4nel
*/
public interface ExtFSEntry extends FSEntry {
-
public void setParent(FSDirectory parent);
}
Modified: trunk/fs/src/fs/org/jnode/fs/jifs/JIFileSystem.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jifs/JIFileSystem.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/jifs/JIFileSystem.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -117,4 +117,21 @@
protected FSEntry createRootEntry() throws IOException {
return null;
}
+
+
+ public long getFreeSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getTotalSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getUsableSpace() {
+ // TODO implement me
+ return 0;
+ }
+
}
Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFileSystem.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFileSystem.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFileSystem.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -103,4 +103,20 @@
// TODO Auto-generated method stub
return null;
}
+
+
+ public long getFreeSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getTotalSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getUsableSpace() {
+ // TODO implement me
+ return 0;
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/service/def/FileSystemAPIImpl.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/service/def/FileSystemAPIImpl.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/service/def/FileSystemAPIImpl.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -99,9 +99,9 @@
*
* @param file
*/
- public boolean canRead(String file) {
- // TODO implement me
- return true;
+ public boolean canRead(String file) throws IOException {
+ final FSEntry entry = getEntry(file);
+ return (entry != null) && (entry.getAccessRights().canRead());
}
/**
@@ -109,12 +109,44 @@
*
* @param file
*/
- public boolean canWrite(String file) {
- // TODO implement me
- return false;
+ public boolean canWrite(String file) throws IOException {
+ final FSEntry entry = getEntry(file);
+ return (entry != null) && (entry.getAccessRights().canWrite());
}
/**
+ * Can the given file be executed to?
+ *
+ * @param file
+ */
+ public boolean canExecute(String file) throws IOException {
+ final FSEntry entry = getEntry(file);
+ return (entry != null) && (entry.getAccessRights().canExecute());
+ }
+
+
+ public boolean setReadable(String file, boolean enable,
+ boolean owneronly) throws IOException
+ {
+ final FSEntry entry = getEntry(file);
+ return (entry != null) && (entry.getAccessRights().setReadable(enable, owneronly));
+ }
+
+ public boolean setWritable(String file, boolean enable,
+ boolean owneronly) throws IOException
+ {
+ final FSEntry entry = getEntry(file);
+ return (entry != null) && (entry.getAccessRights().setWritable(enable, owneronly));
+ }
+
+ public boolean setExecutable(String file, boolean enable,
+ boolean owneronly) throws IOException
+ {
+ final FSEntry entry = getEntry(file);
+ return (entry != null) && (entry.getAccessRights().setExecutable(enable, owneronly));
+ }
+
+ /**
* Gets the length in bytes of the given file or 0 if the file does not
* exist.
*
@@ -180,8 +212,9 @@
* @throws IOException
*/
public void setReadOnly(String file) throws IOException {
- throw new IOException("Not implemented yet");
- // TODO implement me
+ setReadable(file, true, true);
+ setWritable(file, false, true);
+ setExecutable(file, false, true);
}
/**
@@ -274,14 +307,13 @@
} catch (IOException ex) {
// Not found
log.debug("parent.getEntry failed", ex);
- ex.printStackTrace();
return null;
}
} else {
return null;
}
} catch (IOException e) {
- log.debug("Filesystem.getRootEntry failed", e);
+ log.debug("Filesystem.getEntry failed", e);
return null;
}
@@ -404,7 +436,7 @@
*
* @param file
* absolute path
- * @return the directory entry, null if not exite or not a directory
+ * @return the directory entry, null if not exist or not a directory
* @throws IOException
*/
private FSDirectory getParentDirectoryEntry(String file) throws IOException {
@@ -463,4 +495,38 @@
return (idx >= 0) ? path.substring(idx + 1) : path;
}
}
+
+ public long getTotalSpace(String path) throws IOException
+ {
+ final FSEntry entry = getEntry(path);
+ long length = 0L;
+ if(entry != null)
+ {
+ length = entry.getFileSystem().getTotalSpace();
+ }
+ return length;
+ }
+
+ public long getFreeSpace(String path) throws IOException
+ {
+ final FSEntry entry = getEntry(path);
+ long length = 0L;
+ if(entry != null)
+ {
+ length = entry.getFileSystem().getFreeSpace();
+ }
+ return length;
+ }
+
+ public long getUsableSpace(String path) throws IOException
+ {
+ final FSEntry entry = getEntry(path);
+ long length = 0L;
+ if(entry != null)
+ {
+ length = entry.getFileSystem().getUsableSpace();
+ }
+ return length;
+ }
+
}
Modified: trunk/fs/src/fs/org/jnode/fs/service/def/VirtualFS.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/service/def/VirtualFS.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/service/def/VirtualFS.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -92,4 +92,20 @@
final void unregisterFileSystem(Device dev) {
root.unregisterFileSystem(dev);
}
+
+
+ public long getFreeSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getTotalSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getUsableSpace() {
+ // TODO implement me
+ return 0;
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/smbfs/SMBFileSystem.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/smbfs/SMBFileSystem.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/smbfs/SMBFileSystem.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -91,4 +91,19 @@
public boolean isReadOnly() {
return true;
}
+
+ public long getFreeSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getTotalSpace() {
+ // TODO implement me
+ return 0;
+ }
+
+ public long getUsableSpace() {
+ // TODO implement me
+ return 0;
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/spi/AbstractFSEntry.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/spi/AbstractFSEntry.java 2007-06-30 11:56:19 UTC (rev 3336)
+++ trunk/fs/src/fs/org/jnode/fs/spi/AbstractFSEntry.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -64,7 +64,7 @@
private long lastModified;
/** access rights of the entry */
- private FSAccessRights rights;
+ final private FSAccessRights rights;
/** Parent directory of the entry */
private FSDirectory parent; // parent is null for a root
@@ -104,7 +104,7 @@
this.table = table;
this.lastModified = System.currentTimeMillis();
this.parent = parent;
- //TODO : this.rights = ???????;
+ this.rights = new UnixFSAccessRights(fs);
}
/**
Added: trunk/fs/src/fs/org/jnode/fs/spi/UnixFSAccessRights.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/spi/UnixFSAccessRights.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/fs/spi/UnixFSAccessRights.java 2007-06-30 11:58:44 UTC (rev 3337)
@@ -0,0 +1,178 @@
+package org.jnode.fs.spi;
+
+import java.io.IOException;
+import java.security.Principal;
+import java.security.acl.Group;
+import java.util.BitSet;
+
+import org.jnode.fs.FSAccessRights;
+import org.jnode.fs.FileSystem;
+
+import sun.security.acl.GroupImpl;
+
+import com.sun.security.auth.UserPrincipal;
+
+/**
+ *
+ * @author Fabien DUMINY (fduminy at jnode.org)
+ *
+ */
+public class UnixFSAccessRights implements FSAccessRights
+{
+ final private FileSystem filesystem;
+
+ private Principal owner;
+ private Group group;
+
+ final private Rights ownerRights = new Rights(true, true, true);
+ final private Rights groupRights = new Rights();
+ final private Rights worldRights = new Rights();
+
+
+ public UnixFSAccessRights(FileSystem filesystem)
+ {
+ if(filesystem == null)
+ {
+ throw new NullPointerException("filesystem can't be null");
+ }
+ this.filesystem = filesystem;
+
+ // TODO manages users & groups in JNode
+ owner = new UserPrincipal("root");
+ group = new GroupImpl("admins");
+ group.addMember(owner);
+ }
+
+ private Principal getUser()
+ {
+ // TODO manages users & groups in JNode
+ // we should find the user from the context
+ return owner;
+ }
+
+ private Rights getUserRights()
+ {
+ Principal user = getUser();
+
+ Rights rights = worldRights;
+ if(owner.equals(user))
+ {
+ rights = ownerRights;
+ }
+ else if(group.isMember(user))
+ {
+ rights = groupRights;
+ }
+
+ return rights;
+ }
+
+ public boolean canExecute() {
+ return getUserRights().isExecute();
+ }
+
+ public boolean canRead() {
+ return getUserRights().isRead();
+ }
+
+ public boolean canWrite() {
+ return getUserRights().isWrite();
+ }
+
+ public Principal getOwner() {
+ return owner;
+ }
+
+ public boolean setExecutable(boolean enable, boolean owneronly)
+ {
+ if(!owner.equals(getUser()))
+ {
+ return false;
+ }
+
+ ownerRights.setExecute(enable);
+ if(!owneronly)
+ {
+ groupRights.setExecute(enable);
+ worldRights.setExecute(enable);
+ }
+ return true;
+ }
+
+ public boolean setReadable(boolean enable, boolean owneronly)
+ {
+ if(!owner.equals(getUser()))
+ {
+ return false;
+ }
+
+ ownerRights.setRead(enable);
+ if(!owneronly)
+ {
+ groupRights.setRead(enable);
+ worldRights.setRead(enable);
+ }
+ return true;
+ }
+
+ public boolean setWritable(boolean enable, boolean owneronly)
+ {
+ if(!owner.equals(getUser()))
+ {
+ return false;
+ }
+
+ ownerRights.setWrite(enable);
+ if(!owneronly)
+ {
+ groupRights.setWrite(enable);
+ worldRights.setWrite(enable);
+ }
+ return true;
+ }
+
+ public FileSystem getFileSystem() {
+ return filesystem;
+ }
+
+ public boolean isValid() {
+ return true;
+ }
+
+ private static class Rights
+ {
+ private boolean read = false;
+ private boolean write = false;
+ private boolean execute = false;
+
+ public Rights()
+ {
+ this(false, false, false);
+ }
+
+ public Rights(boolean read, boolean write, boolean execute) {
+ this.read = read;
+ this.write = write;
+ this.execute = execute;
+ }
+
+ public boolean isRead() {
+ return read;
+ }
+ public void setRead(boolean read) {
+ this.read = read;
+ }
+ public boolean isWrite() {
+ return write;
+ }
+ public void setWrite(boolean write) {
+ this.write = write;
+ }
+ public boolean isExecute() {
+ return execute;
+ }
+ public void setExecute(boolean execute) {
+ this.execute = execute;
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|