Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
api:filesystem [2015/01/30 22:29]
solra_bizna [Filesystem API] Touch on how to create a custom filesystem. I've only shallowly tested this, I hope I'm not wrong...
api:filesystem [2015/02/01 01:42]
solra_bizna [Filesystem API] Eek! That isn't actually possible in current version!
Line 10: Line 10:
   Returns the canonical form of the specified path, i.e. a path containing no "​indirections"​ such as `.` or `..`. For example, the paths `/​tmp/​../​bin/​ls.lua` and `/​bin/​./​ls.lua` are equivalent, and their canonical form is `/​bin/​ls.lua`.  ​   Returns the canonical form of the specified path, i.e. a path containing no "​indirections"​ such as `.` or `..`. For example, the paths `/​tmp/​../​bin/​ls.lua` and `/​bin/​./​ls.lua` are equivalent, and their canonical form is `/​bin/​ls.lua`.  ​
   Note that this function truncates relative paths to their topmost "​known"​ directory. For example, `../​bin/​ls.lua` becomes `bin/​ls.lua`. It stays a relative path, however - mind the lack of a leading slash.   Note that this function truncates relative paths to their topmost "​known"​ directory. For example, `../​bin/​ls.lua` becomes `bin/​ls.lua`. It stays a relative path, however - mind the lack of a leading slash.
 +- `filesystem.segments(path:​ string): table`  ​
 +  Returns a table containing one entry for each //​canonical//​ segment of the given path.
 +  Examples:  ​
 +  * `filesystem.segments("​foo/​bar"​)` -> `{"​foo","​bar"​}`
 +  * `filesystem.segments("​foo/​bar/​../​baz"​)` -> `{"​foo","​baz"​}`
 +
 - `filesystem.concat(pathA:​ string, pathB: string[, ...]): string`  ​ - `filesystem.concat(pathA:​ string, pathB: string[, ...]): string`  ​
   Concatenates two or more paths. Note that all paths other than the first are treated as relative paths, even if they begin with a slash. The canonical form of the resulting concatenated path is returned, so `fs.concat("​a",​ "​.."​)` results in an empty string.   Concatenates two or more paths. Note that all paths other than the first are treated as relative paths, even if they begin with a slash. The canonical form of the resulting concatenated path is returned, so `fs.concat("​a",​ "​.."​)` results in an empty string.
Line 21: Line 27:
 - `filesystem.mount(fs:​ table or string, path: string): boolean or nil, string`  ​ - `filesystem.mount(fs:​ table or string, path: string): boolean or nil, string`  ​
   Mounts a file system at the specified path. The first parameter can be either a file system component'​s proxy, its address or its label. The second is a path into the global directory tree. Returns true if the file system was successfully mounted, `nil` and an error message otherwise.   Mounts a file system at the specified path. The first parameter can be either a file system component'​s proxy, its address or its label. The second is a path into the global directory tree. Returns true if the file system was successfully mounted, `nil` and an error message otherwise.
-  Hard disks, floppy disks, and the /tmp filesystem are accessed via a proxy of an actual [[component:​filesystem|Filesystem component]]. By passing to `filesystem.mount` your own "​proxy"​ table that implements its own equivalents to that component'​s operations, you can make your own filesystems. Compression,​ encryption, union mounts, software RAID, and networking are just a few possibilities. 
 - `filesystem.mounts():​ function -> table, string`  ​ - `filesystem.mounts():​ function -> table, string`  ​
   Returns an iterator function over all currently mounted file system component'​s proxies and the paths at which they are mounted. This means the same proxy may appear multiple times, but with different mount paths.   Returns an iterator function over all currently mounted file system component'​s proxies and the paths at which they are mounted. This means the same proxy may appear multiple times, but with different mount paths.