X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe-android/blobdiff_plain/04a5abaece151705e9bd7026653f79938a7a2fbc..a5ec891a1f3cbe4ae9aad5d2252f39b483ed543e:/sys.scala diff --git a/sys.scala b/sys.scala index 51ac170..6931431 100644 --- a/sys.scala +++ b/sys.scala @@ -438,8 +438,11 @@ def stat(path: String): sys.FileInfo = stat(path.toCString); 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._; @@ -637,19 +640,15 @@ object FileImplicits { 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; } } } @@ -662,6 +661,12 @@ object FileImplicits { 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);