Skip to main content
Light Dark System

Vfs Mode

<et2-vfs-mode> | Et2VfsMode

Unix permission string renderer. Migrated from classic et2_vfsMode (et2_widget_vfs.ts). No dependency on any legacy et2_vfs* class.

When to use it

<et2-vfs-mode> turns a numeric unix file mode into the drwxr-xr-x string ls -l would print. It is a pure formatter - it takes the number the VFS stores and makes it readable. There is nothing to edit and no way to change permissions through it.

Examples

What it does

The value is the raw mode; the widget shows the permission string. The same string is also the element’s tooltip, so a narrow column stays readable.

value octal shown as
33188 100644
33261 100755
16877 40755
33152 100600
41471 120777
<table>
    <thead>
        <tr><th align="left">value</th><th align="left">octal</th><th align="left">shown as</th></tr>
    </thead>
    <tbody>
        <tr><td>33188</td><td>100644</td><td><et2-vfs-mode value="33188"></et2-vfs-mode></td></tr>
        <tr><td>33261</td><td>100755</td><td><et2-vfs-mode value="33261"></et2-vfs-mode></td></tr>
        <tr><td>16877</td><td>40755</td><td><et2-vfs-mode value="16877"></et2-vfs-mode></td></tr>
        <tr><td>33152</td><td>100600</td><td><et2-vfs-mode value="33152"></et2-vfs-mode></td></tr>
        <tr><td>41471</td><td>120777</td><td><et2-vfs-mode value="41471"></et2-vfs-mode></td></tr>
    </tbody>
</table>

The first character is the file type, taken from the same S_IFMT bits the C library uses: - for a regular file, d for a directory, l for a symlink, and s, p, c or b for the rarer kinds.

<et2-vfs-mode value="24996"></et2-vfs-mode>

That is 0o60644, a block device. The type is matched against the whole S_IFMT field rather than by testing single bits, which matters here: a block device’s bits contain a character device’s, so a per-bit test reports the wrong type for it.

Special permission bits

set-UID, set-GID and the sticky bit each replace the execute character of their own triplet. Following ls, the replacement is lowercase when that execute bit is set too and uppercase when it is not - so the letter tells you the special bit is on, and its case tells you whether the file is actually executable.

octal bit shown as
104755 set-UID, owner executable
104655 set-UID, not owner executable
102755 set-GID, group executable
41777 sticky, world executable
41776 sticky, not world executable
107777 all three at once
<table>
    <thead>
        <tr><th align="left">octal</th><th align="left">bit</th><th align="left">shown as</th></tr>
    </thead>
    <tbody>
        <tr><td>104755</td><td>set-UID, owner executable</td><td><et2-vfs-mode value="35309"></et2-vfs-mode></td></tr>
        <tr><td>104655</td><td>set-UID, not owner executable</td><td><et2-vfs-mode value="35245"></et2-vfs-mode></td></tr>
        <tr><td>102755</td><td>set-GID, group executable</td><td><et2-vfs-mode value="34285"></et2-vfs-mode></td></tr>
        <tr><td>41777</td><td>sticky, world executable</td><td><et2-vfs-mode value="17407"></et2-vfs-mode></td></tr>
        <tr><td>41776</td><td>sticky, not world executable</td><td><et2-vfs-mode value="17406"></et2-vfs-mode></td></tr>
        <tr><td>107777</td><td>all three at once</td><td><et2-vfs-mode value="36863"></et2-vfs-mode></td></tr>
    </tbody>
</table>

In a row

The usual use is a filemanager column. The widget accepts the whole row object as well as a bare number, and picks mode out of it - so binding it to the row is enough.

<et2-vfs-mode id="${row}[mode]"/>

Nothing to show

An empty, missing or non-numeric value renders nothing at all, rather than a row of dashes that would look like a real set of permissions.

a real mode ← shows
an empty value ← empty
no value at all ← empty
not a number ← empty
<table>
    <tbody>
        <tr><td>a real mode</td><td><et2-vfs-mode value="33188"></et2-vfs-mode></td><td>&larr; shows</td></tr>
        <tr><td>an empty value</td><td><et2-vfs-mode value=""></et2-vfs-mode></td><td>&larr; empty</td></tr>
        <tr><td>no value at all</td><td><et2-vfs-mode></et2-vfs-mode></td><td>&larr; empty</td></tr>
        <tr><td>not a number</td><td><et2-vfs-mode value="rw-r--r--"></et2-vfs-mode></td><td>&larr; empty</td></tr>
    </tbody>
</table>

From javascript

Et2VfsMode.formatMode() is the same conversion as a static method, for when you need the string outside a widget - in a tooltip, a confirmation message, a log line.

import {Et2VfsMode} from "../../api/js/etemplate/Et2Vfs/Et2VfsMode";

Et2VfsMode.formatMode(33188);        // "-rw-r--r--"
Et2VfsMode.formatMode({mode: 16877}); // "drwxr-xr-x"

Properties

Name Description Reflects Type Default
perms
Read / write / execute bit masks. Record { 'x': 0x1, // Execute 'w': 0x2, // Write 'r': 0x4 // Read }
S_IFMT
Mask selecting the file-type bits out of a mode, everything below it is permissions. number 0xF000
sticky
Sticky / set-UID / set-GID overrides. Each replaces the execute character of one permission triplet. The positions are indices into the 9 character permission string only - the leading file-type character is prepended afterwards and must not be counted here. {mask : number, char : string, position : number}[] [ {mask: 0x200, char: "T", position: 8}, // Sticky, replaces world execute {mask: 0x400, char: "S", position: 5}, // sGID, replaces group execute {mask: 0x800, char: "S", position: 2} // SUID, replaces owner execute ]
types
File-type masks, to be compared against the S_IFMT bits as a whole. Several of these share bits (block special 0x6000 contains character special 0x2000, for example), so a plain mode & mask test matches the wrong type - mask with S_IFMT and compare for equality instead, which also makes the result independent of the order declared here. Record { 'l': 0xA000, // link 's': 0xC000, // Socket 'p': 0x1000, // FIFO pipe 'c': 0x2000, // Character special 'd': 0x4000, // Directory 'b': 0x6000, // Block special '-': 0x8000 // Regular }

Learn more about attributes and properties.

Inherited properties (23)

Description

Name Description
accesskey Accesskey provides a hint for generating a keyboard shortcut for the current element. The attribute value must consist of a single printable character.
actions Set Actions on the widget Each action is defined as an object: move: { type: “drop”, acceptedTypes: “mail”, icon: “move”, caption: “Move to” onExecute: javascript:mail_move” } This will turn the widget into a drop target for “mail” drag types. When “mail” drag types are dropped, the global function mail_move(egwAction action, egwActionObject sender) will be called. The ID of the dragged “mail” will be in sender.id, some information about the sender will be in sender.context. The etemplate2 widget involved can typically be found in action.parent.data.widget, so your handler can operate in the widget context easily. The location varies depending on your action though. It might be action.parent.parent.data.widget To customise how the actions are handled for a particular widget, override _link_actions(). It handles the more widget-specific parts.
activateLinks Scan the value, and if there are any links (URL, mailto:) then wrap them in a clickable tag
align Used by Et2Box to determine alignment. Allowed values are left, right
class CSS Class. This class is applied to the outside, on the web component itself. Due to how WebComponents work, this might not change anything inside the component.
data Set the dataset from a CSV
deferredProperties Any attribute that refers to row content cannot be resolved immediately, but some like booleans cannot stay a string because it’s a boolean attribute. We store them for later, and parse when they’re fully in their row. If you are creating a widget that can go in a nextmatch row, and it has boolean attributes that can change for each row, add those attributes into deferredProperties
disabled Defines whether this widget is visibly disabled. The widget is still visible, but clearly cannot be interacted with. Widgets disabled in the template will not return a value to the application code, even if re-enabled via javascript before submitting. To allow a disabled widget to be re-enabled and return a value, disable via javascript in the app’s et2_ready() instead of an attribute in the template file.
dom_id Get the actual DOM ID, which has been prefixed to make sure it’s unique.
extraLinkPopup widthxheight, if popup should be used, eg. 640x480
extraLinkTarget Extra link target Goes with href. If provided, that’s the target for opening the link.
hidden The widget is not visible. As far as the user is concerned, the widget does not exist. Widgets hidden with an attribute in the template may not be created in the DOM, and will not return a value. Widgets can be hidden after creation, and they may return a value if hidden this way.
href Link URL If provided, will be clickable and open this URL
id Get the ID of the widget
label The label of the widget This is usually displayed in some way. It’s also important for accessability. This is defined in the parent somewhere, and re-defining it causes labels to disappear
noLang Disable any translations for the widget
parentId Parent is different than what is specified in the template / hierarchy. Widget ID of another node to insert this node into instead of the normal location
statustext Tooltip which is shown for this element on hover
styles WebComponent *
value Numeric mode value, or a row object that carries .mode.
options Get property-values as object
supportedWidgetClasses et2_widget compatability

LitElement

Name Description
updateComplete A read-only promise that resolves when the component has finished updating.

Methods

Name Description Arguments
formatMode() Convert a numeric mode into a d---rwx--- style permission string. Matches what ls -l prints, and the server-side EGroupware\Api\Vfs::int2mode() for the same mode. _value: number | string | undefined | null

Learn more about methods.

Inherited methods (21)

Description

Name Description
checkCreateNamespace() Checks whether a namespace exists for this element in the content array. If yes, an own perspective of the content array is created. If not, the parent content manager is used. Constructor attributes are passed in case a child needs to make decisions
clone() Creates a copy of this widget.
createElementFromNode() Create a et2_widget from an XML node. First the type and attributes are read from the node. Then the readonly & modifications arrays are checked for changes specific to the loaded data. Then the appropriate constructor is called. After the constructor returns, the widget has a chance to further initialize itself from the XML node when the widget’s loadFromXML() method is called with the node.
getArrayMgr() Returns the array manager object for the given part
getArrayMgrs() Returns an associative array containing the top-most array managers.
getChildren() Get child widgets Use .children to get web component children
getInstanceManager() Returns the instance manager
getPath() Returns the path into the data array. By default, array manager takes care of this, but some extensions need to override this
getRoot() Returns the base widget Usually this is the same as getInstanceManager().widgetContainer
loadFromXML() Loads the widget tree from an XML node
loadingFinished() Needed for legacy compatability.
parseXMLAttrs() The parseXMLAttrs function takes an XML DOM attributes object and adds the given attributes to the _target associative array. This function also parses the legacyOptions. N.B. This is only used for legacy widgets. WebComponents use transformAttributes() and do their own handling of attributes.
set_label() NOT the setter, since we cannot add to the DOM before connectedCallback() TODO: This is not best practice. Should just set property, DOM modification should be done in render https://lit-element.polymer-project.org/guide/templates#design-a-performant-template
setArrayMgr() Sets the array manager for the given part
setArrayMgrs() Sets all array manager objects - this function can be used to set the root array managers of the container object.
setInstanceManager() Set the instance manager Normally this is not needed as it’s set on the top-level container, and we just return that reference
_handleClick() Click handler calling custom handler set via onclick attribute to this.onclick
destroy() et2_widget compatability
set_class() Set the widget class
set_disabled() Wrapper on this.disabled because legacy had it.
set_statustext() supports legacy set_statustext

Belongs to

Filemanager