1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-13 03:30:29 +00:00

Add isReadOnly to fs.attributes (#639)

This commit is contained in:
Lupus590 2021-01-07 16:36:25 +00:00 committed by GitHub
parent cc5e972cfc
commit 41226371f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -471,8 +471,8 @@ public class FSAPI implements ILuaAPI
/**
* 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 class FSAPI implements ILuaAPI
* @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 class FSAPI implements ILuaAPI
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 )

View File

@ -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))