Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 35740 invoked from network); 13 Oct 2009 10:25:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 13 Oct 2009 10:25:15 -0000 Received: (qmail 66636 invoked by uid 500); 13 Oct 2009 10:25:15 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 66564 invoked by uid 500); 13 Oct 2009 10:25:14 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 66555 invoked by uid 99); 13 Oct 2009 10:25:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Oct 2009 10:25:14 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Oct 2009 10:25:09 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id F3C1423888FF; Tue, 13 Oct 2009 10:24:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r824666 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/io/ native/include/ native/os/unix/ native/shared/ Date: Tue, 13 Oct 2009 10:24:48 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091013102448.F3C1423888FF@eris.apache.org> Author: mturk Date: Tue Oct 13 10:24:46 2009 New Revision: 824666 URL: http://svn.apache.org/viewvc?rev=824666&view=rev Log: Add Directory class Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java (with props) 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/LocalStrings.properties commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Status.java commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c commons/sandbox/runtime/trunk/src/main/native/shared/error.c Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java?rev=824666&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java (added) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java Tue Oct 13 10:24:46 2009 @@ -0,0 +1,204 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.commons.runtime.io; + +import org.apache.commons.runtime.Descriptor; +import org.apache.commons.runtime.exception.ClosedDescriptorException; +import org.apache.commons.runtime.exception.AsyncClosedDescriptorException; +import org.apache.commons.runtime.exception.InvalidDescriptorException; +import org.apache.commons.runtime.exception.OverlappingFileLockException; +import org.apache.commons.runtime.exception.TimeoutException; +import org.apache.commons.runtime.util.StringManager; +import java.io.Closeable; +import java.io.Flushable; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.SyncFailedException; +import java.util.Enumeration; +import java.util.EnumSet; +import java.util.Vector; + +/** + * Directory class. + */ +public class Directory implements Closeable +{ + /* Directory descriptor object + */ + private Descriptor dd; + + /** + * Close this file. + * @see java.io.Closeable#close() + * @throws IOException if an I/O error occurs. + */ + public final void close() + throws IOException + { + dd.close(); + } + + private static native Descriptor open0(String path) + throws FileNotFoundException, IOException, SecurityException; + /** + * Open a {@code Directory} for reading. + */ + public Directory(File path) + throws FileNotFoundException, IOException, SecurityException + { + dd = open0(path.getPath()); + } + + private static native FileInfo read1(Descriptor dd) + throws IOException; + public FileInfo read() + throws IOException + { + return read1(dd); + } + + private static native void rewind0(Descriptor dd); + public void rewind() + { + rewind0(dd); + } + + private static native long tell0(Descriptor dd) + throws IOException; + public long tell() + throws IOException + { + return tell0(dd); + } + + private static native void seek0(Descriptor dd, long off); + public void seek(long off) + { + seek0(dd, off); + } + + private static native int mkdir0(String path, int perms); + private static native int mkdir1(String path, int perms); + + public static boolean create(File path, EnumSet prot) + throws FileNotFoundException, IOException, SecurityException + { + int rc; + + rc = mkdir0(path.getPath(), FileProtection.bitmapOf(prot)); + if (rc == 0) + return true; + if (Status.STATUS_IS_EEXIST(rc)) + return false; + if (Status.STATUS_IS_ENOENT(rc)) { + /* Missing interediate dir + */ + throw new FileNotFoundException(); + } + if (Status.STATUS_IS_EACCES(rc)) { + /* Missing interediate dir + */ + throw new SecurityException(); + } + throw new IOException(Status.describe(rc)); + } + + public static boolean createRecursive(File path, + EnumSet prot) + throws IOException, SecurityException + { + int rc; + + rc = mkdir1(path.getPath(), FileProtection.bitmapOf(prot)); + if (rc == 0) + return true; + if (Status.STATUS_IS_EEXIST(rc)) + return false; + if (Status.STATUS_IS_EACCES(rc)) { + /* Missing interediate dir + */ + throw new SecurityException(); + } + throw new IOException(Status.describe(rc)); + } + + private static native String tmpdir0(String path, String prefix) + throws IOException, SecurityException; + + /** + * Creates a new temporary directory with {@code prefix} inside + * directory specified by {@code path}. + *

+ *

+ * @param path Where to create a new drectory. + * @param prefix The prefix for the new drectory. + * @return Newly created unique directory abstract path. + * + * @throws IOException in case of error. + * @throws SecurityException if Write access to the directory specified + * by {@code path} is denied. + */ + public static File createTemp(File path, String prefix) + throws IOException, SecurityException + { + String tmp = tmpdir0(path.getPath(), prefix); + return new File(tmp, FileType.DIR); + } + + /** + * Creates a new temporary directory with {@code prefix}. + *

+ *

+ * @param prefix The prefix for the new drectory. + * @return Newly created unique directory abstract path. + * + * @throws IOException in case of error. + * @throws SecurityException if Write access to the system temporary + * directory is denied. + */ + public static File createTemp(String prefix) + throws IOException, SecurityException + { + String tmp = tmpdir0(null, prefix); + return new File(tmp, FileType.DIR); + } + + private static File tmpDir; + private static native String tmpdir1(String paths); + /** + * Get system temporary directory path. + * + * @param searchPath {@link java.io.File#pathSeparator} delimited list of + * directories to use as temporary directory. Firts one that is + * accessible will be used. + * @return Temporary directory {@code File} instance. + * @throws SecurityException if Write access to directories listed inside + * {@code searchPath} is denied. + */ + public synchronized static File getTemp(String searchPath) + throws SecurityException + { + String dir = tmpdir1(searchPath); + if (dir == null) + throw new SecurityException(); + tmpDir = new File(dir, FileType.DIR); + + return tmpDir; + } + + +} Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Directory.java ------------------------------------------------------------------------------ svn:eol-style = native 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=824666&r1=824665&r2=824666&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 Tue Oct 13 10:24:46 2009 @@ -23,6 +23,7 @@ import org.apache.commons.runtime.Descriptor; import org.apache.commons.runtime.Group; import org.apache.commons.runtime.User; +import org.apache.commons.runtime.util.StringManager; /** * An abstract representation of file and directory pathnames that @@ -154,6 +155,22 @@ } /** + * Create new {@code File} instance by converting the given pathname + * into an abstract pathname. If the given string is the empty path, + * then the result is the empty abstract pathname. + * + * @param pathname A pathname string. + * @throws NullPointerException If the {@code pathname} is {@code null}. + */ + public File(String pathname, FileType type) + throws NullPointerException + { + super(pathname); + if (type != null) + fileType = type.valueOf(); + } + + /** * Creates a new {@code File} instance by converting the given * {@code file:} URI into an abstract pathname. *

@@ -387,7 +404,7 @@ return new File(link, FileType.LNK.valueOf()); } else { - throw new IOException("Symlink exists and points to a different path"); + throw new IOException(Local.sm.get("symlink.EEXIST")); } } Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/LocalStrings.properties URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/LocalStrings.properties?rev=824666&r1=824665&r2=824666&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/LocalStrings.properties (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/LocalStrings.properties Tue Oct 13 10:24:46 2009 @@ -14,3 +14,4 @@ # limitations under the License. file.EEXIST=File already exsts and CREATE and EXCL FileOpenMode was given +symlink.EEXIST=Symbolic link exists and points to a different path Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Status.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Status.java?rev=824666&r1=824665&r2=824666&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Status.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Status.java Tue Oct 13 10:24:46 2009 @@ -429,6 +429,12 @@ return is0(EEXIST, s); } + /** File exists */ + public static boolean STATUS_IS_ENOENT(int s) + { + return is0(ENOENT, s); + } + public static native String describe(int s); /* TODO: Implement the remaining of STATUS_IS methods */ } Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h?rev=824666&r1=824665&r2=824666&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h Tue Oct 13 10:24:46 2009 @@ -42,6 +42,7 @@ ACR_EX_ENOMEM, /* java/lang/OutOfMemoryError */ ACR_EX_ENULL, /* java/lang/NullPointerException */ ACR_EX_EINVAL, /* java/lang/IllegalArgumentException */ + ACR_EX_EISTATE, /* java/lang/IllegalStateException */ ACR_EX_EINDEX, /* java/lang/IndexOutOfBoundsException */ ACR_EX_ECCAST, /* java/lang/ClassCastException */ ACR_EX_EINSTANCE, /* java/lang/InstantiationException */ @@ -50,6 +51,7 @@ ACR_EX_ULINK, /* java/lang/UnsatisfiedLinkError */ ACR_EX_ENOTIMPL, /* java/lang/UnsupportedOperationException */ ACR_EX_EIO, /* java/io/IOException */ + ACR_EX_EINTR, /* java/io/InterruptedIOException */ ACR_EX_ENOTFOUND, /* java/io/FileNotFoundException */ ACR_EX_ESYNC, /* java/io/SyncFailedException */ ACR_EX_ESOCK, /* java/net/SocketException */ Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c?rev=824666&r1=824665&r2=824666&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c Tue Oct 13 10:24:46 2009 @@ -26,6 +26,10 @@ #include "acr_file.h" #include "acr_fileio.h" +/* Platform includes + */ +#include + static int file_cleanup(void *file, int type, unsigned int flags) { int rc = ACR_EBADF; @@ -418,12 +422,33 @@ static int wait_for_io_or_timeout(acr_file_t *f, int for_read) { int rc; + acr_time_t prev, nexttime; + struct timeval t; + int timeout = f->timeout; + f->ppoll.fd = f->fd; f->ppoll.events = for_read ? POLLIN : POLLOUT; - - do { - rc = poll(&f->ppoll, 1, f->timeout); - } while (rc == -1 && errno == EINTR); + /* Store the the current time + */ + gettimeofday(&t, NULL); + prev = ((acr_time_t)t.tv_sec * 1000) + t.tv_usec / 1000; + for (;;) { + rc = poll(&f->ppoll, 1, timeout); + if (rc == -1 && errno == EINTR) { + if (timeout >= 0) { + gettimeofday(&t, NULL); + nexttime = ((acr_time_t)t.tv_sec * 1000) + t.tv_usec / 1000; + timeout -= (int)(nexttime - prev); + if (timeout <= 0) { + rc = 0; + break; + } + prev = nexttime; + } + } + else + break; + } if (rc == 0) return ACR_TIMEUP; else if (rc > 0) Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=824666&r1=824665&r2=824666&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Tue Oct 13 10:24:46 2009 @@ -30,6 +30,7 @@ "java/lang/OutOfMemoryError", "java/lang/NullPointerException", "java/lang/IllegalArgumentException", + "java/lang/IllegalStateException", "java/lang/IndexOutOfBoundsException", "java/lang/ClassCastException", "java/lang/InstantiationException", @@ -38,6 +39,7 @@ "java/lang/UnsatisfiedLinkError", "java/lang/UnsupportedOperationException", "java/io/IOException", + "java/io/InterruptedIOException", "java/io/FileNotFoundException", "java/io/SyncFailedException", "java/net/SocketException",