GNU TeXmacsUser manualReferenceAboutEnglish
The remote file system

1.Remote URLs

Remote documents are accessed through the tmfs mechanism: a URL of the form tmfs://class/name is loaded and saved by Scheme handlers declared with tmfs-load-handler, tmfs-save-handler, tmfs-title-handler, tmfs-permission-handler, etc. The general mechanism is described in the TeXmacs file system; here we only describe the classes used for remote work. In all of them, the first component of name is the server name as known to the client, optionally followed by :port.

tmfs://remote-file/server/~pseudo/path

A file stored on the server. The ~pseudo component is the home directory of the user pseudo; it is also used by find-server-for-name to select the right connection when several accounts on the same server are logged in.

tmfs://remote-dir/server/~pseudo/path

A directory, displayed as a document in the style remote-file-browser.

tmfs://remote-file/server/time=t/~pseudo/path

The file as it was at time t (seconds since the epoch). The same time= component may be used for directories.

tmfs://live/server/name, tmfs://live-list/server

A live document and the list of live documents of the user (

client/client-live.scm

).

tmfs://chat/server/room, tmfs://chat-rooms/server

A chat room (or the mail box when the room name starts with mail-) and the list of chat rooms (

client/client-chat.scm

).

tmfs://shared/server

The list of resources shared with the user.

The tmfs handlers of the client are registered lazily: the boot file

init-texmacs.scm

contains (lazy-tmfs-handler (client client-tmfs) remote-file), so that the client modules are loaded when a remote URL is first opened. See Connecting to a TeXmacs server and Permissions and access control for the user interface.

2.Server side organization

2.1.Resources

The remote file system is a “database file system”. Each file or directory is a resource, i.e. an entry of the server database whose identifier is called a resource identifier (rid). The fields used by

server/server-tmfs.scm

are:

type

"file", "dir", "version-list", "live", "chat-room", …

name, dir

The last component of the name and the identifier of the parent directory. Home directories are directory entries named ~pseudo, without dir field, created together with the user by server-set-user-info.

owner, readable, writable

Access rights, checked with db-allow?. A new file or directory inherits all non reserved properties of its parent (copy-properties with inherit-property?), in particular its access rights.

location

The path of the contents relative to the repository $TEXMACS_HOME_PATH/server.

version-list, version-nr, version-by, version-msg

Version information, see below.

Names are resolved component by component: file-name->resource maps a name such as localhost/~joe/notes/a.tm to its resource by searching a directory named ~joe, then an entry named notes in it, etc. (search-file); resource->file-name performs the converse operation. Renaming or moving a resource is thus just a change of its name or dir field (see remote-rename on the client, which uses remote-set-field).

2.2.The repository

The contents of files are stored as ordinary files below $TEXMACS_HOME_PATH/server, one file per version. repository-add chooses a fresh location for a new resource: it descends into randomly numbered subdirectories 0…9 until it finds a directory without a subdirectory _, creates that subdirectory and puts the file rid.suffix in it. The relative location is recorded in the location field, and repository-get returns the absolute path. Files are never overwritten: a new version is a new resource with a new location. This is why incremental backups with hard links are efficient.

2.3.Services

All file system services take a name without the tmfs://remote-file/ prefix and start with the macro with-remote-context, which splits off the server name and an optional time=t component, and binds db-time accordingly; modifications are refused with Error: cannot modify past when a time is given. The actual work is done by functions server-file-create, server-file-load, server-file-save, server-file-remove, server-dir-create, server-dir-load and server-dir-remove, which return (:error message) or a success tag such as (:created rid) or (:loaded doc), and can therefore be reused by other services (the synchronization services do so).

(remote-file-load name)
(service: load a file)

Checks that the user is logged in and has read access, and returns the file contents as a string in TeXmacs format, after replacing large subtrees by cache-ref trees if the client supports the tree cache.

(remote-file-create name doc msg), (remote-file-save name doc msg)
(service: create or save a file)

Create a file (write access to the directory is required) or save a new version of it (write access to the file is required). msg is an optional commit message (or #f). Saving a document identical to the stored one does nothing.

(remote-dir-load name)
(service: list a directory)

Returns a list of entries (short-name full-name dir? props) for the readable children, where props is the database entry with user identifiers replaced by pseudos.

The other services are remote-dir-create, remote-file-remove, remote-dir-remove (recursive), remote-identifier (map a name to its resource identifier, or to (rid time) for past versions, or #f) and remote-get-versions. The generic database services of

server/server-db.scm

(remote-get-field, remote-set-field, remote-get-entry, remote-search, …) give access to the properties of resources; they accept an identifier of the form returned by remote-identifier, so that properties of past versions can be read (but not written: Error: cannot rewrite history). The permission editor of the client (open-permissions-editor) and the title handler of remote files are built on these services.

2.4.Versions on the server

Every remote file has a version list, an entry of type "version-list" whose field version-current is a counter, and every version of the file is a separate file resource with fields version-list (the list), version-nr, version-by (the user who saved it) and optionally version-msg. server-file-save:

  1. refuses the save if the version number of the current resource differs from the counter (Error: version number mismatch);

  2. does nothing if the contents did not change;

  3. otherwise increments the counter, creates a new resource for the new contents with the same name, directory and inherited properties, and removes the old resource.

Since the database keeps history, removed resources remain visible at earlier times, which is how time= URLs work. The service remote-get-versions returns, for each version readable by the user, (rid date name by msg), and the client builds the page tmfs://history/… from it (compute-remote-versions). The generic versioning menu works for remote files because

client-tmfs.scm

overloads versioned?, version-status, version-history, commit-buffer-message, version-revision?, version-head, etc. with :require (remote-file? …); committing with a message simply saves the buffer with remote-commit-message bound to the message. See also Versioning and document comparison.

Remark 1. The client does not send the version on which its modifications are based, and the version number of the current resource always equals the counter in normal operation. Concurrent saves of the same remote file from two clients are therefore resolved by “last writer wins”; the earlier version remains available in the history.

3.Client side

client/client-tmfs.scm

implements:

Most of these functions follow the same pattern: find the connection with find-server-for-name, send a request with client-remote-eval, and update a buffer in the continuation.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".