ServerJS/Filesystem API/Names: Difference between revisions

m (→‎General Preferences: weighed in on make/create show of hands)
 
Line 21: Line 21:
*** Kris Kowal
*** Kris Kowal
*** Wes Garland
*** Wes Garland
*** (Python: os.path.exists, Ruby: exist?, exists?, Java: exists, JSExt: access, Spidermonkey: Helma: v8cgi: JSExt: EJScript: Synchronet: exists, jslibs: exist)
*** (Python: os.path.exists, Ruby: exist?, exists?, Java: exists, JSExt: access, Spidermonkey: Helma: v8cgi: JSExt: EJScript: Synchronet: exists, jslibs: exist, PHP: file_exists)


* whether a symbolic link or file exists at a given path: receives a path and returns whether that path, joined on the current working directory, corresponds to a file, albeit a broken symbolic link, that exists.
* whether a symbolic link or file exists at a given path: receives a path and returns whether that path, joined on the current working directory, corresponds to a file, albeit a broken symbolic link, that exists.
Line 35: Line 35:
* moves a file from a source to a target path.  Both paths are joined on the current working directory.
* moves a file from a source to a target path.  Both paths are joined on the current working directory.
** move(source, target):
** move(source, target):
** (Ruby: move, Python: shutil.move, Java: File.renameTo)
** (Ruby: move, Python: shutil.move, Java: File.renameTo, PHP: rename)


* renames a file: receives two paths.  The first is a path, joined on the current working directory, that refers to the file to rename.  The second argument is a path relative to the former file's fully qualified path.
* renames a file: receives two paths.  The first is a path, joined on the current working directory, that refers to the file to rename.  The second argument is a path relative to the former file's fully qualified path.
Line 45: Line 45:
* copies a file from a source to a target path.  Both paths are joined on the current working directory.
* copies a file from a source to a target path.  Both paths are joined on the current working directory.
** copy(source, target):
** copy(source, target):
** (Ruby: copy, systemCopy, Python: copy, Unix: cp)
** (Ruby: copy, systemCopy, Python:PHP: copy, Unix: cp)


* copies a file and its recursive contents to a target path.  Both paths are joined on the current working directory.  If "synbolicLinks" is truthy, symbolic links in the source tree are represented as symbolic links in the new tree; if falsy, the contents of the linked files are copied to the new tree.  If ignore is given, it must be a relation that will receive as its arguments the directory being visited by copytree(), and a list of its contents. Since this is called recursively (or walking an equivalent iteration), the ignore relation will be called once for each directory that is copied. The relation must return a sequence of directory and file names relative to the current directory (i.e. a subset of the items in its second argument); these names will then be ignored in the copy process.
* copies a file and its recursive contents to a target path.  Both paths are joined on the current working directory.  If "synbolicLinks" is truthy, symbolic links in the source tree are represented as symbolic links in the new tree; if falsy, the contents of the linked files are copied to the new tree.  If ignore is given, it must be a relation that will receive as its arguments the directory being visited by copytree(), and a list of its contents. Since this is called recursively (or walking an equivalent iteration), the ignore relation will be called once for each directory that is copied. The relation must return a sequence of directory and file names relative to the current directory (i.e. a subset of the items in its second argument); these names will then be ignored in the copy process.
Line 60: Line 60:
** mkdir(path)
** mkdir(path)
*** Kevin Dangoor
*** Kevin Dangoor
** (Unix: mkdir)
** (Unix:PHP: mkdir)


* creates recursive directories.  Makes all intermediate-level directories needed to contain the leaf directory. Throws an exception if the leaf directory already exists or cannot be created. The default mode is 0777 (octal). On some systems, mode is ignored. Where it is used, the current umask value is first masked out.
* creates recursive directories.  Makes all intermediate-level directories needed to contain the leaf directory. Throws an exception if the leaf directory already exists or cannot be created. The default mode is 0777 (octal). On some systems, mode is ignored. Where it is used, the current umask value is first masked out.
Line 74: Line 74:
** mkdirs(path)
** mkdirs(path)
*** Kevin Dangoor
*** Kevin Dangoor
** (PHP: mkdir(path, mode, true))


* removes a file.
* removes a file.
Line 83: Line 84:
** unlink(path):
** unlink(path):
*** Wes Garland
*** Wes Garland
** (Ruby: unlink, delete, Python: unlink, remove, Java: delete, Posix: unlink, Unix: rm, Spidermonkey: Helma: EJScript: Synchronet: remove, jslibs: Delete)
** (Ruby: unlink, delete, Python: unlink, remove, Java: delete, Posix:PHP: unlink, Unix: rm, Spidermonkey: Helma: EJScript: Synchronet: remove, jslibs: Delete)


* removes a file or directory and its recursive contents.
* removes a file or directory and its recursive contents.
Line 96: Line 97:
** link(source, target):
** link(source, target):
*** uncontested
*** uncontested
** (Python: link, Ruby: link, Unix: ln)
** (Python:Ruby:PHP: link, Unix: ln)


* creates a symbolic link on a given "target" file name.  The source path becomes the text of the symbolic link, which the underlying system will join on the containing directory when it's followed, while the target path is joined on the current working directory.
* creates a symbolic link on a given "target" file name.  The source path becomes the text of the symbolic link, which the underlying system will join on the containing directory when it's followed, while the target path is joined on the current working directory.
Line 105: Line 106:
** link(source, target, "symbolic"):
** link(source, target, "symbolic"):
*** Kris Kowal (as a compromise)
*** Kris Kowal (as a compromise)
** (Ruby: symlink, Python: symlink, Unix: ln -s)
** (Ruby:Python:PHP: symlink, Unix: ln -s)


* creates an empty file at a given path in its implied base directory.  The path is resolved relative to the current working directory.  Accepts an optional ``Permissions`` object (or a duck-type thereof, or the, typically octal, numeric representation of permissions in Unix) that notes which permissions the file will be created with, assuming that those permissions are in the "umask".
* creates an empty file at a given path in its implied base directory.  The path is resolved relative to the current working directory.  Accepts an optional ``Permissions`` object (or a duck-type thereof, or the, typically octal, numeric representation of permissions in Unix) that notes which permissions the file will be created with, assuming that those permissions are in the "umask".
Line 113: Line 114:
*** Kris Kowal,
*** Kris Kowal,
*** Wes Garland
*** Wes Garland
** (Java: createNewFile, Posix: creat, Unix: touch)
** (Java: createNewFile, Posix: creat, Unix:PHP: touch)


* truncates a the file at a given path.  Accepts an optional length that default to zero.  The path is resolved on the current working directory.
* truncates a the file at a given path.  Accepts an optional length that default to zero.  The path is resolved on the current working directory.
Line 119: Line 120:
** omit entirely:
** omit entirely:
*** Kris Kowal
*** Kris Kowal
** (Ruby: truncate, Python: ftruncate applies to open files only)
** (Ruby: truncate, Python:PHP: ftruncate applies to open files only)


* updates the stat/metadata of the file at a given path.  Accepts a stat object.  Implicitly updates the time that the file's metadata/stat was updated to the current time, regardless of the metadata modification time provided by the stat object.
* updates the stat/metadata of the file at a given path.  Accepts a stat object.  Implicitly updates the time that the file's metadata/stat was updated to the current time, regardless of the metadata modification time provided by the stat object.
Line 132: Line 133:
** touch(path, [date]):
** touch(path, [date]):
*** Kris Kowal
*** Kris Kowal
** (Unix: touch)
** (Unix:PHP: touch)


* locks the file at a given path with either an exclusive or shared advisory lock.  The path is resolved on the current working directory.  Blocks until the lock is acquired, or if a timeout is defined, when that timeout occurs.
* locks the file at a given path with either an exclusive or shared advisory lock.  The path is resolved on the current working directory.  Blocks until the lock is acquired, or if a timeout is defined, when that timeout occurs.
Line 139: Line 140:
*** Kris Kowal
*** Kris Kowal
** lock(path, "rw|")
** lock(path, "rw|")
** (Posix: lock, Python: lock)
** (Posix:Python: lock)


* attempts to acquire an advisory lock a file at a given path but does not block.  The path is resolved relative to the current working directory.  Does not block if the file is not lockable.  Returns whether the lock was obtained.
* attempts to acquire an advisory lock a file at a given path but does not block.  The path is resolved relative to the current working directory.  Does not block if the file is not lockable.  Returns whether the lock was obtained.
Line 145: Line 146:
** tryLock(path, "shared|exclusive"):
** tryLock(path, "shared|exclusive"):
** lock(path, "rw")
** lock(path, "rw")
** (Python: lock)
** (Python: lock, PHP: flock($handle))


* releases a lock for a given path.
* releases a lock for a given path.
Line 152: Line 153:
** lock(path, "unlock")
** lock(path, "unlock")
** lock(path, "u")
** lock(path, "u")
** (Python: lock)
** (Python: lock, PHP: flock($handle, LOCK_UN))


* retrieves an object that represents the metadata of a distinct file, for a given path.  The path is resolved relative to the current working directory.  The returned object has the properties described in the Stat API.
* retrieves an object that represents the metadata of a distinct file, for a given path.  The path is resolved relative to the current working directory.  The returned object has the properties described in the Stat API.
** stat(path):
** stat(path):
*** Mario Valente
*** Mario Valente
** (Python: os.stat, Ruby: File.stat, Posix: stat)
** (Python: os.stat, Ruby: File.stat, Posix:PHP: stat)


* retrieves an object that represents the metadata of a distinct file or symbolic link to a file at a given path.  The path is resolved relative to the current working directory.  The returned object has the properties described in the Stat API.
* retrieves an object that represents the metadata of a distinct file or symbolic link to a file at a given path.  The path is resolved relative to the current working directory.  The returned object has the properties described in the Stat API.
Line 166: Line 167:
** stat(path, "link"):
** stat(path, "link"):
*** Kris Kowal (as a compromise)
*** Kris Kowal (as a compromise)
** (Python: os.lstat, Ruby: File.lstat)
** (Python: os.lstat, Ruby: File.lstat, PHP: lstat)


* returns the size of the corresponding file.
* returns the size of the corresponding file.
** size(path)
** size(path)
** (Python: size, Ruby: size?: Java: length, Posix: st_size)
** (Python: size, Ruby: size?: Java: length, Posix: st_size, PHP: filesize)


* returns the total size of a tree of files.
* returns the total size of a tree of files.
Line 195: Line 196:
* return a Dir object for a given directory path.  The path is resolved relative to the current working directory.  The Dir object is an bidirectional iterator of a snapshot of the contents of the directory, and may be either a lazy Array or genuine array, depending on whether the underlying implementation can retrieve indicies on demand.
* return a Dir object for a given directory path.  The path is resolved relative to the current working directory.  The Dir object is an bidirectional iterator of a snapshot of the contents of the directory, and may be either a lazy Array or genuine array, depending on whether the underlying implementation can retrieve indicies on demand.
** list(path)
** list(path)
** (Python: os.listdir, Ruby: Dir)
** (Python: os.listdir, Ruby: Dir, PHP: dir)


* returns an object that, like a Dir, supports the iterator protocol (next, prev) and the Array protocol (length, [index]) for all files that match a given glob pattern.
* returns an object that, like a Dir, supports the iterator protocol (next, prev) and the Array protocol (length, [index]) for all files that match a given glob pattern.
Confirmed users
11

edits