From 41226371f3b5fd35f48b6d39c2e8e0c277125b21 Mon Sep 17 00:00:00 2001 From: Lupus590 Date: Thu, 7 Jan 2021 16:36:25 +0000 Subject: [PATCH] Add isReadOnly to fs.attributes (#639) --- src/main/java/dan200/computercraft/core/apis/FSAPI.java | 7 ++++--- src/test/resources/test-rom/spec/apis/fs_spec.lua | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/dan200/computercraft/core/apis/FSAPI.java b/src/main/java/dan200/computercraft/core/apis/FSAPI.java index 6ae65f62a..fada96ecd 100644 --- a/src/main/java/dan200/computercraft/core/apis/FSAPI.java +++ b/src/main/java/dan200/computercraft/core/apis/FSAPI.java @@ -471,8 +471,8 @@ public final Object getCapacity( String path ) throws LuaException /** * Get attributes about a specific file or folder. * - * The returned attributes table contains information about the size of the file, whether it is a directory, and - * when it was created and last modified. + * The returned attributes table contains information about the size of the file, whether it is a directory, + * when it was created and last modified, and whether it is read only. * * The creation and modification times are given as the number of milliseconds since the UNIX epoch. This may be * given to {@link OSAPI#date} in order to convert it to more usable form. @@ -480,7 +480,7 @@ public final Object getCapacity( String path ) throws LuaException * @param path The path to get attributes for. * @return The resulting attributes. * @throws LuaException If the path does not exist. - * @cc.treturn { size = number, isDir = boolean, created = number, modified = number } The resulting attributes. + * @cc.treturn { size = number, isDir = boolean, isReadOnly = boolean, created = number, modified = number } The resulting attributes. * @see #getSize If you only care about the file's size. * @see #isDir If you only care whether a path is a directory or not. */ @@ -496,6 +496,7 @@ public final Map attributes( String path ) throws LuaException result.put( "created", getFileTime( attributes.creationTime() ) ); result.put( "size", attributes.isDirectory() ? 0 : attributes.size() ); result.put( "isDir", attributes.isDirectory() ); + result.put( "isReadOnly", fileSystem.isReadOnly( path ) ); return result; } catch( FileSystemException e ) diff --git a/src/test/resources/test-rom/spec/apis/fs_spec.lua b/src/test/resources/test-rom/spec/apis/fs_spec.lua index 9a861af34..32503598e 100644 --- a/src/test/resources/test-rom/spec/apis/fs_spec.lua +++ b/src/test/resources/test-rom/spec/apis/fs_spec.lua @@ -194,7 +194,7 @@ describe("The fs library", function() end) it("returns information about read-only mounts", function() - expect(fs.attributes("rom")):matches { isDir = true, size = 0 } + expect(fs.attributes("rom")):matches { isDir = true, size = 0, isReadOnly = true } end) it("returns information about files", function() @@ -206,7 +206,7 @@ describe("The fs library", function() h.close() local attributes = fs.attributes("tmp/basic-file") - expect(attributes):matches { isDir = false, size = 25 } + expect(attributes):matches { isDir = false, size = 25, isReadOnly = false } if attributes.created - now >= 1000 then fail(("Expected created time (%d) to be within 1000ms of now (%d"):format(attributes.created, now))