def lstat(path: String): sys.FileInfo = lstat(path.toCString);
object FileInfo extends Enumeration {
- /* A simple enumeration of things a file might be. */
- val FIFO, CHR, DIR, BLK, REG, LNK, SOCK, UNK = Value;
+ /* A simple enumeration of things a file might be.
+ *
+ * `HDLNK' is a hard link, used in `tar' files.
+ */
+ val FIFO, CHR, DIR, BLK, REG, LNK, SOCK, HDLNK, UNK = Value;
type Type = Value;
}
import FileInfo._;
def islnk_! : Boolean = statish(lstat _, _.ftype == LNK, false);
def issock_! : Boolean = statish(stat _, _.ftype == SOCK, false);
+ /* Slightly more cooked file operations. */
def remove_!() {
/* Delete a file, or directory, whatever it is. */
- while (true) {
- try { unlink_!(); return; }
- catch {
- case SystemError(ENOENT, _) => return;
- case SystemError(EISDIR, _) => ok;
- }
- try { rmdir_!(); return; }
- catch {
- case SystemError(ENOENT, _) => return;
- case SystemError(ENOTDIR, _) => ok;
- }
+ try { unlink_!(); return; }
+ catch {
+ case SystemError(ENOENT, _) => return;
+ case SystemError(EISDIR, _) =>
+ try { rmdir_!(); return; }
+ catch { case SystemError(ENOENT, _) => return; }
}
}
walk(file);
}
+ def mkdirNew_!() {
+ /* Make a directory if there's nothing there already. */
+ try { mkdir_!(); }
+ catch { case SystemError(EEXIST, _) => ok; }
+ }
+
/* File locking. */
def lock_!(flags: Int): FileLock = new FileLock(file.getPath, flags);
def lock_!(): FileLock = lock_!(LKF_EXCL | 0x1b6);