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/04/20 12:49:02 UTC
svn commit: r766651 - in /commons/sandbox/runtime/trunk/src:
main/java/org/apache/commons/runtime/io/File.java
test/org/apache/commons/runtime/TestFile.java
Author: mturk
Date: Mon Apr 20 10:49:01 2009
New Revision: 766651
URL: http://svn.apache.org/viewvc?rev=766651&view=rev
Log:
Add some javadocs
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java
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=766651&r1=766650&r2=766651&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 Mon Apr 20 10:49:01 2009
@@ -188,30 +188,101 @@
return fileType == 6;
}
- public static boolean createSymbolicLink(String targetName, String linkName)
+ /**
+ * Creates a symbolic link named {@code link} which contains the string
+ * {@code target}.
+ * <p>
+ * Symbolic links are interpreted at run-time as if the contents of
+ * the link had been substituted into the path being followed to find a
+ * file or directory.
+ * </p>
+ * <p>
+ * Symbolic links may contain {@code ..} path components, which
+ * (if used at the start of the link) refer to the parent
+ * directories of that in which the link resides.
+ * </p>
+ * <p>
+ * A symbolic link (also known as a soft link) may point to an existing
+ * file or to a nonexistent one; the latter case is known as a
+ * <em>dangling link</em>.
+ * </p>
+ *
+ * @param target The abstract path the {@code link} points to.
+ * @param link The symbolic link name.
+ * @return {@code true} if symbolic link was created, false if it already
+ * exists.
+ * @throws IOException in case of error.
+ */
+ public static boolean createSymbolicLink(String target, String link)
throws IOException
{
- return mkslink0(targetName, linkName);
+ return mkslink0(target, link);
}
- public File createSymbolicLink(String linkName)
+ /**
+ * Creates a new abstract {@code File} symbolic link instance with
+ * the path {@code link} which contains the string of this {@code File}
+ * isnstance pathname.
+ * <p>
+ * Symbolic links are interpreted at run-time as if the contents of
+ * the link had been substituted into the path being followed to find a
+ * file or directory.
+ * </p>
+ * <p>
+ * Symbolic links may contain {@code ..} path components, which
+ * (if used at the start of the link) refer to the parent
+ * directories of that in which the link resides.
+ * </p>
+ * <p>
+ * A symbolic link (also known as a soft link) may point to an existing
+ * file or to a nonexistent one; the latter case is known as a
+ * <em>dangling link</em>.
+ * </p>
+ *
+ * @param link The symbolic link name.
+ * @return New {@code File} instance containing symbolic link to this
+ * file instance.
+ * @throws IOException in case of error.
+ */
+ public File createSymbolicLink(String link)
throws IOException
{
- mkslink0(getPath(), linkName);
// False means EEXIST, so just consider it opened
- // TODO: readlink and see if target matches.
- if (getPath().equals(target0(linkName))) {
- return new File(linkName, 6);
+ // Check is made wather it points to the same target
+ mkslink0(getPath(), link);
+ if (getPath().equals(target0(link))) {
+ return new File(link, 6);
}
else {
throw new IOException("Symlink exists and points to a different path");
}
}
- public File getTarget()
+ /**
+ * Return target pathname of this abstract {@code File} instance.
+ *
+ * @return Pathname this {@code File} points to.
+ * @throws IOException if this {@code File} is not symbolic link
+ * or an I/O error occured.
+ */
+ public String getTargetPath()
throws IOException
{
- return new File(target0(getPath()));
+ return target0(getPath());
+ }
+
+ /**
+ * Return new abstract {@code File} target instance of this
+ * abstract {@code File} instance.
+ *
+ * @return New {@code File} instance this {@code File} points to.
+ * @throws IOException if this {@code File} is not symbolic link
+ * or an I/O error occured.
+ */
+ public File getTargetFile()
+ throws IOException
+ {
+ return new File(getTargetPath());
}
}
Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java?rev=766651&r1=766650&r2=766651&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFile.java Mon Apr 20 10:49:01 2009
@@ -122,7 +122,7 @@
FileType t = symlnk.getFileType();
assertEquals("Name", "bar", symlnk.getPath());
assertEquals("Type", FileType.LNK, t);
- File target = symlnk.getTarget();
+ File target = symlnk.getTargetFile();
assertEquals("Target", source.getPath(), target.getPath());
symlnk.delete();