You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/10/23 15:09:18 UTC
svn commit: r829046 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/io/
java/org/apache/commons/runtime/platform/windows/ native/include/
native/os/unix/ native/os/win32/ native/shared/
Author: mturk
Date: Fri Oct 23 13:09:18 2009
New Revision: 829046
URL: http://svn.apache.org/viewvc?rev=829046&view=rev
Log:
Use private path type instead FileType
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileAttributes.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLockType.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileOpenMode.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileProtection.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMap.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Path.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/KeyAccessRights.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ServiceControlsAccepted.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ServiceType.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/VariantType.java
commons/sandbox/runtime/trunk/src/main/native/include/acr_fileio.h
commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/path.c
commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java Fri Oct 23 13:09:18 2009
@@ -70,7 +70,7 @@
private static native Path tmpdir0(String pathname, String prefix)
throws IOException, SecurityException;
private static native Path tmpdir1(String srchpath)
- throws SecurityException;
+ throws IOException, SecurityException;
private static native FileInfo stat0(String pathname, boolean link,
boolean full)
throws IOException, SecurityException;
@@ -123,8 +123,11 @@
* @see FileType
*/
public static FileType getFileType(Path path)
- throws IOException, SecurityException
+ throws NullPointerException, IOException, SecurityException
{
+ if (path == null) {
+ throw new NullPointerException();
+ }
int type = ftype0(path.toString());
return FileType.valueOf(type);
}
@@ -141,55 +144,77 @@
* @see FileType
*/
public static FileType getFileType(final Descriptor fd)
- throws IOException
+ throws NullPointerException, IOException, SecurityException
{
+ if (fd == null) {
+ throw new NullPointerException();
+ }
return FileWrapper.ftype(fd);
}
public static EnumSet<FileProtection> getFileProtection(Path path)
- throws IOException, SecurityException
+ throws NullPointerException, IOException, SecurityException
{
+ if (path == null) {
+ throw new NullPointerException();
+ }
int mode = fprot0(path.toString());
return FileProtection.valueOf(mode);
}
public static boolean setFileProtection(Path path, EnumSet<FileProtection> prot)
- throws IOException, SecurityException
+ throws IOException, NullPointerException, SecurityException
{
+ if (path == null) {
+ throw new NullPointerException();
+ }
return chmod0(path.toString(), FileProtection.bitmapOf(prot));
}
public static boolean setFileProtection(Path path, FileProtection... prot)
- throws IOException, SecurityException
+ throws IOException, NullPointerException, SecurityException
{
+ if (path == null) {
+ throw new NullPointerException();
+ }
return chmod0(path.toString(), FileProtection.bitmapOf(prot));
}
public static boolean setOwner(Path path, User user, Group group)
- throws IOException, SecurityException
+ throws IOException, NullPointerException, SecurityException
{
+ if (path == null || user == null || group == null) {
+ throw new NullPointerException();
+ }
return chown0(path.toString(), user.Id, group.Id);
}
public static boolean setOwner(Path path, User user)
- throws IOException, SecurityException
+ throws IOException, NullPointerException, SecurityException
{
+ if (path == null || user == null) {
+ throw new NullPointerException();
+ }
return chown0(path.toString(), user.Id, null);
}
public static boolean setOwner(Path path, Group group)
- throws IOException, SecurityException
+ throws IOException, NullPointerException, SecurityException
{
+ if (path == null || group == null) {
+ throw new NullPointerException();
+ }
return chown0(path.toString(), null, group.Id);
}
public static Descriptor create(Path path, EnumSet<FileOpenMode> mode)
throws FileNotFoundException, IOException, IllegalArgumentException,
- SecurityException
+ NullPointerException, SecurityException
{
- if (mode == null)
- throw new IllegalArgumentException();
+ if (path == null || mode == null) {
+ throw new NullPointerException();
+ }
mode.add(FileOpenMode.CREATE);
Descriptor fd = FileWrapper.open(path, mode);
if (fd == null) {
@@ -201,8 +226,11 @@
public static Descriptor open(Path path, EnumSet<FileOpenMode> mode)
throws FileNotFoundException, IOException, IllegalArgumentException,
- SecurityException
+ NullPointerException, SecurityException
{
+ if (path == null || mode == null) {
+ throw new NullPointerException();
+ }
Descriptor fd = FileWrapper.open(path, mode);
if (fd == null) {
// File exists and EXCL mode was given
@@ -224,6 +252,9 @@
throws FileNotFoundException, IOException, IllegalArgumentException,
SecurityException
{
+ if (path == null || mode == null || prot == null) {
+ throw new NullPointerException();
+ }
Descriptor fd = FileWrapper.open(path, mode, prot);
if (fd == null) {
// File exists and EXCL mode was given
@@ -249,6 +280,15 @@
* attributes are platform specific and may involve more than simply
* setting permission bits.
* </p>
+ * <p>
+ * Changing file attributes require both {@code attribute} and
+ * {@code mask} parameters to be set for a desired attribute change.
+ * </p>
+ * The following code will chage the file attributes to read only.
+ * <pre>
+ * File.setAttributtes(somePath, FileAttributes.READONLY,
+ * FileAttributes.READONLY);
+ * </pre>
*
* @param attributes Set of {@code FileAttributes}.
* <pre>
@@ -257,6 +297,14 @@
* HIDDEN - make the file hidden
* </pre>
* @param mask Mask of valid bits in attributes.
+ * <pre>
+ * READONLY - readonly attribute will be set if present in attributes
+ * otherwise it will be cleared.
+ * EXECUTABLE - executable attribute will be set if present in attributes
+ * otherwise it will be cleared.
+ * HIDDEN - hidden attribute will be set if present in attributes
+ * otherwise it will be cleared.
+ * </pre>
* @return {@code true} if the file attributes were set.
* @throws IOException If an I/O error occured.
* @throws SecurityException If Search permission is denied for one of
@@ -267,6 +315,9 @@
EnumSet<FileAttributes> mask)
throws IOException, SecurityException
{
+ if (path == null) {
+ throw new NullPointerException();
+ }
return attrs0(path.toString(),
FileAttributes.bitmapOf(attributes),
FileAttributes.bitmapOf(mask));
@@ -291,6 +342,9 @@
public static EnumSet<FileAttributes> getFileAttributes(Path path)
throws IOException, SecurityException
{
+ if (path == null) {
+ throw new NullPointerException();
+ }
return FileAttributes.valueOf(attrg0(path.toString()));
}
@@ -307,6 +361,9 @@
public static boolean isSymbolicLink(Path path)
throws IOException, SecurityException
{
+ if (path == null) {
+ throw new NullPointerException();
+ }
int type = ftype0(path.toString());
return type == FileType.LNK.valueOf();
}
@@ -349,6 +406,9 @@
public static boolean createSymbolicLink(Path target, Path link)
throws IOException, SecurityException, UnsupportedOperationException
{
+ if (target == null || link == null) {
+ throw new NullPointerException();
+ }
return mkslink0(target.toString(), link.toString());
}
@@ -377,6 +437,9 @@
public static boolean createHardLink(String target, String link)
throws IOException, SecurityException
{
+ if (target == null || link == null) {
+ throw new NullPointerException();
+ }
return mkhlink0(target, link);
}
@@ -394,6 +457,9 @@
public static Path createTempDirectory(String prefix)
throws IOException, SecurityException
{
+ if (prefix == null) {
+ throw new NullPointerException();
+ }
return tmpdir0(null, prefix);
}
@@ -413,6 +479,9 @@
public static Path createTempDirectory(Path path, String prefix)
throws IOException, SecurityException
{
+ if (path == null) {
+ throw new NullPointerException();
+ }
return tmpdir0(path.toString(), prefix);
}
@@ -429,10 +498,10 @@
public static FileStream createTempFileStream(String prefix, String suffix,
Path directory,
boolean preserve)
- throws IOException, IllegalArgumentException, SecurityException
+ throws IOException, NullPointerException, SecurityException
{
if (prefix == null) {
- throw new IllegalArgumentException();
+ throw new NullPointerException();
}
Descriptor fd = FileWrapper.mktemp(directory, prefix, suffix, preserve);
return new FileStreamImpl(fd);
@@ -447,10 +516,10 @@
*/
public static FileStream createTempFileStream(String prefix, String suffix,
boolean preserve)
- throws IOException, IllegalArgumentException, SecurityException
+ throws IOException, NullPointerException, SecurityException
{
if (prefix == null) {
- throw new IllegalArgumentException();
+ throw new NullPointerException();
}
Descriptor fd = FileWrapper.mktemp(prefix, suffix, preserve);
return new FileStreamImpl(fd);
@@ -465,10 +534,10 @@
*/
public static Descriptor createTemp(String prefix, String suffix,
Path directory, boolean preserve)
- throws IOException, IllegalArgumentException, SecurityException
+ throws IOException, NullPointerException, SecurityException
{
if (prefix == null) {
- throw new IllegalArgumentException();
+ throw new NullPointerException();
}
return FileWrapper.mktemp(directory, prefix, suffix, preserve);
}
@@ -482,10 +551,10 @@
*/
public static Descriptor createTemp(String prefix, String suffix,
boolean preserve)
- throws IOException, IllegalArgumentException, SecurityException
+ throws IOException, NullPointerException, SecurityException
{
if (prefix == null) {
- throw new IllegalArgumentException();
+ throw new NullPointerException();
}
return FileWrapper.mktemp(prefix, suffix, preserve);
}
@@ -500,8 +569,11 @@
* component of this abstract {@code File} pathname prefix.
*/
public static Path getTargetPath(Path path)
- throws IOException, SecurityException
+ throws IOException, NullPointerException, SecurityException
{
+ if (path == null) {
+ throw new NullPointerException();
+ }
return target0(path.toString());
}
@@ -515,8 +587,11 @@
* component of this abstract {@code File} pathname prefix.
*/
public static long getFileId(Path path)
- throws IOException, SecurityException
+ throws IOException, NullPointerException, SecurityException
{
+ if (path == null) {
+ throw new NullPointerException();
+ }
return inode0(path.toString());
}
@@ -538,8 +613,11 @@
* @see FileInfo
*/
public static FileInfo getFileInfo(Path path)
- throws IOException, SecurityException
+ throws IOException, NullPointerException, SecurityException
{
+ if (path == null) {
+ throw new NullPointerException();
+ }
return stat0(path.toString(), false, true);
}
@@ -563,13 +641,20 @@
* If some other I/O error occurs.
*/
public static String getFileSystemPath(Descriptor fd)
- throws IOException
+ throws IOException, NullPointerException
{
+ if (fd == null) {
+ throw new NullPointerException();
+ }
return FileWrapper.name(fd);
}
public static int delete(Path path)
+ throws NullPointerException
{
+ if (path == null) {
+ throw new NullPointerException();
+ }
return unlink0(path.toString());
}
@@ -587,8 +672,11 @@
* If some other I/O error occurs.
*/
public static long getLength(Path path)
- throws IOException
+ throws IOException, NullPointerException, SecurityException
{
+ if (path == null) {
+ throw new NullPointerException();
+ }
FileInfo info = stat0(path.toString(), false, false);
return info.Size;
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileAttributes.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileAttributes.java?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileAttributes.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileAttributes.java Fri Oct 23 13:09:18 2009
@@ -68,7 +68,7 @@
public static int bitmapOf(EnumSet<FileAttributes> set)
{
int bitmap = 0;
- if (set != null) {
+ if (set != null && set.size() != 0) {
for (FileAttributes a : set)
bitmap += a.valueOf();
}
@@ -84,7 +84,7 @@
public static int bitmapOf(FileAttributes... set)
{
int bitmap = 0;
- if (set.length != 0) {
+ if (set != null) {
for (FileAttributes a : set)
bitmap += a.valueOf();
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLockType.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLockType.java?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLockType.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileLockType.java Fri Oct 23 13:09:18 2009
@@ -63,7 +63,7 @@
public static int bitmapOf(EnumSet<FileLockType> set)
{
int bitmap = 0;
- if (set != null) {
+ if (set != null && set.size() != 0) {
for (FileLockType t : set)
bitmap += t.valueOf();
}
@@ -79,7 +79,7 @@
public static int bitmapOf(FileLockType... set)
{
int bitmap = 0;
- if (set.length != 0) {
+ if (set != null) {
for (FileLockType t : set)
bitmap += t.valueOf();
}
@@ -106,7 +106,7 @@
public static EnumSet<FileLockType> of(FileLockType... of)
{
EnumSet<FileLockType> set = EnumSet.noneOf(FileLockType.class);
- if (of != null && of.length != 0) {
+ if (of != null) {
for (FileLockType t : of)
set.add(t);
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileOpenMode.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileOpenMode.java?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileOpenMode.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileOpenMode.java Fri Oct 23 13:09:18 2009
@@ -81,7 +81,7 @@
public static int bitmapOf(EnumSet<FileOpenMode> set)
{
int bitmap = 0;
- if (set != null) {
+ if (set != null && set.size() != 0) {
for (FileOpenMode m : set)
bitmap += m.valueOf();
}
@@ -97,7 +97,7 @@
public static int bitmapOf(FileOpenMode... set)
{
int bitmap = 0;
- if (set.length != 0) {
+ if (set != null) {
for (FileOpenMode m : set)
bitmap += m.valueOf();
}
@@ -129,7 +129,7 @@
public static EnumSet<FileOpenMode> of(FileOpenMode... of)
{
EnumSet<FileOpenMode> set = EnumSet.noneOf(FileOpenMode.class);
- if (of != null && of.length != 0) {
+ if (of != null) {
for (FileOpenMode m : of)
set.add(m);
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileProtection.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileProtection.java?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileProtection.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileProtection.java Fri Oct 23 13:09:18 2009
@@ -91,7 +91,7 @@
public static int bitmapOf(FileProtection... set)
{
int bitmap = 0;
- if (set.length != 0) {
+ if (set != null) {
for (FileProtection p : set)
bitmap += p.valueOf();
}
@@ -139,7 +139,7 @@
public static EnumSet<FileProtection> of(FileProtection... of)
{
EnumSet<FileProtection> set = EnumSet.noneOf(FileProtection.class);
- if (of != null && of.length != 0) {
+ if (of != null) {
for (FileProtection p : of)
set.add(p);
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMap.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMap.java?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMap.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/MemoryMap.java Fri Oct 23 13:09:18 2009
@@ -51,8 +51,12 @@
* @param mode Open mode flags.
*/
public MemoryMap(Path path, EnumSet<FileOpenMode> mode)
- throws IOException, IllegalArgumentException, OutOfMemoryError
+ throws IOException, NullPointerException, IllegalArgumentException,
+ OutOfMemoryError, SecurityException
{
+ if (path == null || mode == null) {
+ throw new NullPointerException();
+ }
mp = new MemoryMapProvider(path, mode);
}
@@ -64,9 +68,12 @@
* @param mode Open mode flags.
*/
public MemoryMap(Descriptor fd, EnumSet<FileOpenMode> mode)
- throws IOException, IllegalArgumentException, OutOfMemoryError,
- ClosedDescriptorException
+ throws IOException, NullPointerException, IllegalArgumentException,
+ OutOfMemoryError, SecurityException
{
+ if (fd == null || mode == null) {
+ throw new NullPointerException();
+ }
mp = new MemoryMapProvider(fd, mode);
}
@@ -77,8 +84,7 @@
* @return new {@code Pointer} object
*/
public Pointer map(long offset, long size)
- throws IOException, SecurityException, IllegalArgumentException,
- ClosedDescriptorException
+ throws IOException, SecurityException, IllegalArgumentException
{
return mp.map(offset, size);
}
@@ -89,15 +95,17 @@
* @return new {@code Pointer} object
*/
public Pointer map(long offset)
- throws IOException, SecurityException, IllegalArgumentException,
- ClosedDescriptorException
+ throws IOException, SecurityException, IllegalArgumentException
{
return mp.map(offset);
}
public boolean unmap(Pointer memory)
- throws IOException
+ throws IOException, NullPointerException
{
+ if (memory == null) {
+ throw new NullPointerException();
+ }
return mp.unmap(memory);
}
@@ -106,4 +114,5 @@
{
mp.close();
}
+
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Path.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Path.java?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Path.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Path.java Fri Oct 23 13:09:18 2009
@@ -42,6 +42,11 @@
*/
public final class Path implements Comparable<Path>
{
+ /* Types used when created from known path type.
+ */
+ private static final int UNKNOWN = 0;
+ private static final int NORMALIZED = 1;
+ private static final int CANONICAL = 2;
/**
* Native {@code Path} separator character.
@@ -62,17 +67,20 @@
/**
* {@code true} if file system is case sensitive.
*/
- public static final boolean CASE_SENSITIVE;
+ public static final boolean IS_CASE_SENSITIVE;
private static native void init0(int [] p);
static {
int [] ia = new int[8];
init0(ia);
- SEPARATOR = (char)ia[0];
- DELIMITER = (char)ia[1];
- MAX = ia[2];
- PART_SIZE = ia[3];
- CASE_SENSITIVE = ia[4] == 0;
+ SEPARATOR = (char)ia[0];
+ DELIMITER = (char)ia[1];
+ MAX = ia[2];
+ PART_SIZE = ia[3];
+ /* XXX: Some volumes can be case sensitive
+ * vhile thers cannot.
+ */
+ IS_CASE_SENSITIVE = ia[4] == 1;
}
private static native String normal0(String path)
@@ -94,6 +102,7 @@
throws IOException;
private static native String merge1(String root, String path)
throws IOException;
+
/**
* Merge two paths.
*/
@@ -115,7 +124,7 @@
* Normalized Path
*/
private String path;
- private int type = -1;
+ private int type = UNKNOWN;
/* Created from native.
*/
@@ -148,7 +157,7 @@
* @param child The child pathname string.
* @throws NullPointerException If the {@code child} is {@code null}.
*/
- public Path(String parent, String child)
+ public Path(final String parent, final String child)
throws NullPointerException, IllegalArgumentException
{
if (child == null)
@@ -183,7 +192,7 @@
* @param child The child pathname string.
* @throws NullPointerException If the {@code child} is {@code null}.
*/
- public Path(Path parent, String child)
+ public Path(final Path parent, final String child)
throws NullPointerException, IllegalArgumentException
{
if (child == null)
@@ -203,7 +212,7 @@
* @throws NullPointerException If the {@code path} is {@code null}.
* @throws IllegalArgumentException If the {@code path} is invalid.
*/
- public Path(String path)
+ public Path(final String path)
throws NullPointerException, IllegalArgumentException
{
@@ -212,16 +221,6 @@
this.path = fpath(path);
}
- public Path(String path, FileType type)
- throws NullPointerException, IllegalArgumentException
-
- {
- if (path == null)
- throw new NullPointerException();
- this.path = fpath(path);
- this.type = type.valueOf();
- }
-
public static native int compare0(String path, String other);
public int compareTo(Path other)
{
@@ -239,7 +238,7 @@
* Returned pathname is platform dependant.
* </p>
*/
- public String getPath()
+ public String toNativePath()
{
try {
return native0(path);
@@ -271,14 +270,46 @@
* @return The canonical pathname string denoting the same file or
* directory as this abstract pathname.
*/
- public static String getCanonical(String path)
- throws IOException
+ public static Path getCanonical(final String path)
+ throws NullPointerException, IOException
{
+ if (path == null)
+ throw new NullPointerException();
try {
- return canon0(path);
+ return new Path(canon0(path), CANONICAL);
} catch (Exception ex) {
throw new IOException(ex.getMessage());
}
}
+ public static Path getPath(final String path)
+ throws NullPointerException, IllegalArgumentException
+ {
+ if (path == null)
+ throw new NullPointerException();
+ try {
+ return new Path(normal0(path), NORMALIZED);
+ } catch (IOException ex) {
+ throw new IllegalArgumentException(ex.getMessage());
+ }
+ }
+
+ public boolean isAbsolute()
+ {
+ if (type == CANONICAL)
+ return true;
+ else {
+ char c0 = path.charAt(0);
+ if (c0 == '/')
+ return true;
+ else if (Os.TYPE.contains(OsType.WINDOWS)) {
+ if (path.length() > 2) {
+ if (path.charAt(1) == ':' && path.charAt(2) == '/' &&
+ ((c0 >= 'A' && c0 <= 'Z') || (c0 >= 'a' && c0 <= 'z')))
+ return true;
+ }
+ }
+ return false;
+ }
+ }
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/KeyAccessRights.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/KeyAccessRights.java?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/KeyAccessRights.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/KeyAccessRights.java Fri Oct 23 13:09:18 2009
@@ -78,7 +78,7 @@
public static int bitmapOf(KeyAccessRights... set)
{
int bitmap = 0;
- if (set.length != 0) {
+ if (set != null) {
for (KeyAccessRights a : set)
bitmap += a.valueOf();
}
@@ -105,7 +105,7 @@
public static EnumSet<KeyAccessRights> of(KeyAccessRights... of)
{
EnumSet<KeyAccessRights> set = EnumSet.noneOf(KeyAccessRights.class);
- if (of != null && of.length != 0) {
+ if (of != null) {
for (KeyAccessRights a : of)
set.add(a);
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ServiceControlsAccepted.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ServiceControlsAccepted.java?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ServiceControlsAccepted.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ServiceControlsAccepted.java Fri Oct 23 13:09:18 2009
@@ -81,7 +81,7 @@
public static int bitmapOf(ServiceControlsAccepted... set)
{
int bitmap = 0;
- if (set.length != 0) {
+ if (set != null) {
for (ServiceControlsAccepted a : set)
bitmap += a.valueOf();
}
@@ -107,7 +107,7 @@
public static EnumSet<ServiceControlsAccepted> of(ServiceControlsAccepted... of)
{
EnumSet<ServiceControlsAccepted> set = EnumSet.noneOf(ServiceControlsAccepted.class);
- if (of != null && of.length != 0) {
+ if (of != null) {
for (ServiceControlsAccepted a : of)
set.add(a);
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ServiceType.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ServiceType.java?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ServiceType.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/ServiceType.java Fri Oct 23 13:09:18 2009
@@ -62,7 +62,7 @@
public static int bitmapOf(ServiceType... set)
{
int bitmap = 0;
- if (set.length != 0) {
+ if (set != null) {
for (ServiceType t : set)
bitmap += t.valueOf();
}
@@ -88,7 +88,7 @@
public static EnumSet<ServiceType> of(ServiceType... of)
{
EnumSet<ServiceType> set = EnumSet.noneOf(ServiceType.class);
- if (of != null && of.length != 0) {
+ if (of != null) {
for (ServiceType t : of)
set.add(t);
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/VariantType.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/VariantType.java?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/VariantType.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/VariantType.java Fri Oct 23 13:09:18 2009
@@ -118,10 +118,14 @@
public static int bitmapOf(VariantType... set)
{
int bitmap = 0;
- if (set.length != 0) {
+ if (set != null) {
for (VariantType v : set)
bitmap += v.valueOf();
}
+ else {
+ // Use VT_NULL for null set
+ bitmap = 1;
+ }
return bitmap;
}
@@ -151,7 +155,7 @@
public static EnumSet<VariantType> of(VariantType... of)
{
EnumSet<VariantType> set = EnumSet.noneOf(VariantType.class);
- if (of != null && of.length != 0) {
+ if (of != null) {
for (VariantType t : of)
set.add(t);
}
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_fileio.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_fileio.h?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_fileio.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_fileio.h Fri Oct 23 13:09:18 2009
@@ -23,6 +23,9 @@
extern "C" {
#endif
+#define ACR_PATH_REL 1
+#define ACR_PATH_ABS 2
+
/**
* @file acr_fileio.h
* @brief
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/dir.c Fri Oct 23 13:09:18 2009
@@ -256,7 +256,7 @@
return NULL;
}
else {
- jstring rv = ACR_NewPathObject(_E, ACR_FT_DIR, tmpd);
+ jstring rv = ACR_NewPathObject(_E, ACR_PATH_ABS, tmpd);
x_free(tmpd);
return rv;
}
@@ -273,7 +273,7 @@
tmpd = ACR_TempPathGet(INVALID_HANDLE_VALUE, J2S(paths));
} END_WITH_CSTR(paths);
if (tmpd)
- return ACR_NewPathObject(_E, ACR_FT_DIR, tmpd);
+ return ACR_NewPathObject(_E, ACR_PATH_ABS, tmpd);
else
return NULL;
}
@@ -290,7 +290,7 @@
l = strlen(path);
if (l > 1 && path[l - 1] == '/')
path[l - 1] = '\0';
- return ACR_NewPathObject(_E, ACR_FT_DIR, path);
+ return ACR_NewPathObject(_E, ACR_PATH_ABS, path);
}
ACR_IO_EXPORT_DECLARE(jint, Directory, chdir0)(ACR_JNISTDARGS, jstring path)
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c Fri Oct 23 13:09:18 2009
@@ -212,7 +212,9 @@
else {
ex = 0;
buf[rd] = '\0';
- rv = ACR_NewPathObject(_E, -1, buf);
+ rv = ACR_NewPathObject(_E,
+ buf[0] == '/' ? ACR_PATH_ABS : ACR_PATH_REL,
+ buf);
}
} END_WITH_CSTR(lnkname);
@@ -481,7 +483,7 @@
return NULL;
}
else {
- jstring rv = ACR_NewPathObject(_E, ACR_FT_DIR, tmpd);
+ jstring rv = ACR_NewPathObject(_E, ACR_PATH_ABS, tmpd);
x_free(tmpd);
return rv;
}
@@ -497,7 +499,7 @@
tmpd = ACR_TempPathGet(INVALID_HANDLE_VALUE, J2S(paths));
} END_WITH_CSTR(paths);
if (tmpd)
- return ACR_NewPathObject(_E, ACR_FT_DIR, tmpd);
+ return ACR_NewPathObject(_E, ACR_PATH_ABS, tmpd);
else
return NULL;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/dir.c Fri Oct 23 13:09:18 2009
@@ -103,7 +103,7 @@
for (;;) {
if (!readdir_r(dir, &ds, &dp)) {
if (dp) {
-
+
if (*(dp->d_name) == '.' && (*(dp->d_name + 1) == '\0' ||
(*(dp->d_name + 1) == '.' &&
*(dp->d_name + 2) == '\0'))) {
@@ -245,7 +245,7 @@
return NULL;
}
else {
- jstring rv = ACR_NewPathObject(_E, ACR_FT_DIR, tmpd);
+ jstring rv = ACR_NewPathObject(_E, ACR_PATH_ABS, tmpd);
x_free(tmpd);
return rv;
}
@@ -262,7 +262,7 @@
tmpd = ACR_TempPathGet(INVALID_HANDLE_VALUE, J2W(paths));
} END_WITH_WPATH(paths);
if (tmpd)
- return ACR_NewPathObject(_E, ACR_FT_DIR, tmpd);
+ return ACR_NewPathObject(_E, ACR_PATH_ABS, tmpd);
else
return NULL;
}
@@ -293,7 +293,7 @@
ACR_THROW_IO_IF_ERR(ACR_EOVERFLOW);
return NULL;
}
- return ACR_NewPathObject(_E, ACR_FT_DIR, rcwd);
+ return ACR_NewPathObject(_E, ACR_PATH_ABS, rcwd);
}
ACR_IO_EXPORT_DECLARE(jint, Directory, chdir0)(ACR_JNISTDARGS, jstring path)
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Fri Oct 23 13:09:18 2009
@@ -360,7 +360,7 @@
if (nlen > ACR_HBUFF_LEN)
nlen = ACR_HBUFF_LEN;
wcslcpy(ub, wb, nlen + 1);
- rv = ACR_NewPathObject(_E, -1, ub);
+ rv = ACR_NewPathObject(_E, ACR_PATH_ABS, ub);
break;
case IO_REPARSE_TAG_SYMLINK:
pb = (char *)repb->SymbolicLinkReparseBuffer.PathBuffer;
@@ -369,7 +369,7 @@
wb = (wchar_t *)(pb + noff);
if (wimatch(wb, L"\\\\.\\PIPE\\*", NULL) == ACR_PMATCH_EXACT) {
wcslcpy(ub, wb, nlen + 1);
- rv = ACR_NewPathObject(_E, ACR_FT_PIPE, ub);
+ rv = ACR_NewPathObject(_E, ACR_PATH_ABS, ub);
}
else {
nlen = repb->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof(WCHAR);
@@ -387,7 +387,7 @@
if (nlen > ACR_HBUFF_LEN)
nlen = ACR_HBUFF_LEN;
wcslcpy(ub, wb, nlen + 1);
- rv = aACR_NewPathObject(_E, -1, ub);
+ rv = aACR_NewPathObject(_E, ACR_PATH_ABS, ub);
}
break;
default:
@@ -895,7 +895,7 @@
return NULL;
}
else {
- jstring rv =ACR_NewPathObject(_E, ACR_FT_DIR, tmpd);
+ jstring rv =ACR_NewPathObject(_E, ACR_PATH_ABS, tmpd);
x_free(tmpd);
return rv;
}
@@ -911,7 +911,7 @@
tmpd = ACR_TempPathGet(INVALID_HANDLE_VALUE, J2W(paths));
} END_WITH_WPATH(paths);
if (tmpd)
- return ACR_NewPathObject(_E, ACR_FT_DIR, tmpd);
+ return ACR_NewPathObject(_E, ACR_PATH_ABS, tmpd);
else
return NULL;
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/path.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/path.c?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/path.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/path.c Fri Oct 23 13:09:18 2009
@@ -46,7 +46,7 @@
if (fname[0] == L'U' && fname[1] == L'N' &&
fname[2] == L'C' && fname[3] == L'/') {
fname += 2;
- *fname = L'\\';
+ *fname = L'/';
}
else if (fname[0] == L'U' && fname[1] == L'N' &&
fname[2] == L'/' && fname[3] == L'/') {
@@ -95,6 +95,9 @@
*/
pcopy = NO2UNC(pcopy);
l = wcslen(pcopy);
+ /* Remove any trailing slash unless this is
+ * a single slash path.
+ */
if (l > 1 && pcopy[l - 1] == L'/')
pcopy[l - 1] = L'\0';
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c?rev=829046&r1=829045&r2=829046&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/fsysio.c Fri Oct 23 13:09:18 2009
@@ -150,5 +150,5 @@
ACR_THROW_IO_IF_ERR(ACR_EBADF);
return NULL;
}
- return ACR_NewPathObject(_E, f->type, f->name);
+ return ACR_NewPathObject(_E, ACR_PATH_ABS, f->name);
}