Skip to content

Commit

Permalink
file-list: Also display unix mode/permissions
Browse files Browse the repository at this point in the history
Users sometimes wants to know the mode (permission) flags of objects
without having to show the file details of each individual item.

This patch adds the familiar unix ls-style representation to the file
listing.

In order to closer resemble the familiar/expected style, the common
function convertToNameValueObject() is also augmented with an optional
parameter that allows displaying the file type instead of ? since the
mode bits available doesn't include this information.

Fixes: dCache#202

Signed-off-by: Niklas Edmundsson <[email protected]>
  • Loading branch information
ZNikke committed Dec 5, 2023
1 parent ce970d6 commit 7ced9e6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
}

if (metadata.mode) {
metadata.mode = this.convertToUnixPermissions(metadata.mode);
metadata.mode = this.convertToUnixPermissions(metadata.mode, metadata.fileType);
}

for (const objectKey in metadata) {
Expand Down Expand Up @@ -477,4 +477,4 @@
}
window.customElements.define(FmInnerMapper.is, FmInnerMapper);
</script>
</dom-module>
</dom-module>
19 changes: 17 additions & 2 deletions src/elements/dv-elements/list-view/list-row.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
flex: 1 1 auto;
max-width: calc(100% - 410px);
}
.mode {
width: 12ex;
max-width: 12ex;
min-width: 12ex;
}
.ctime, .qos {
width: 150px;
max-width: 150px;
Expand All @@ -103,7 +108,7 @@
flex: 1 1 auto;
max-width: calc(100% - 50px);
}
.ctime, .qos, .size {
.mode, .ctime, .qos, .size {
display: none;
}
}
Expand All @@ -121,6 +126,7 @@
<div id="rename" class="none"></div>
</div>
</div>
<div class="cell mode">[[fileMode]]</div>
<div class="cell ctime">[[creationTime]]</div>
<div class="cell qos">
<iron-icon id="qos-transition-icon" class="none" icon="arrow-forward"></iron-icon>
Expand Down Expand Up @@ -161,6 +167,10 @@
type: String,
computed:'_computeFilePath(parentPath, fileMetaData.fileName)'
},
fileMode: {
type: String,
computed:'_computeFileMode(fileMetaData.mode, fileMetaData.fileType)'
},
qosValue: {
type: String,
notify: true
Expand Down Expand Up @@ -279,6 +289,11 @@
`${parentPath}${fileName}`: `${parentPath}/${fileName}`;
}

_computeFileMode(mode, type)
{
return this.convertToUnixPermissions(mode, type);
}

_fileCurrentQOSValue(qos)
{

Expand Down Expand Up @@ -362,4 +377,4 @@
}
window.customElements.define(ListRow.is, ListRow);
</script>
</dom-module>
</dom-module>
10 changes: 8 additions & 2 deletions src/elements/dv-elements/table-header/list-row-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
flex: 1 1 auto;
max-width: calc(100% - 418px); /*This is weird, I don't know where the 8px is coming from*/
}
.mode {
width: 12ex;
max-width: 12ex;
min-width: 12ex;
}
.ctime, .qos {
width: 150px;
max-width: 150px;
Expand All @@ -51,7 +56,7 @@
flex: 1 1 auto;
max-width: calc(100% - 50px);
}
.ctime, .qos, .size {
.mode, .ctime, .qos, .size {
display: none;
}
}
Expand All @@ -63,6 +68,7 @@
<div class="row cell">
<div class="cell file-icon">Type</div>
<div class="cell name">Name</div>
<div class="cell mode">Mode</div>
<div class="cell ctime">Creation time</div>
<div class="cell qos">File location</div>
<div class="cell size">Size</div>
Expand All @@ -78,4 +84,4 @@
}
window.customElements.define(ListRowHeader.is, ListRowHeader);
</script>
</dom-module>
</dom-module>
16 changes: 15 additions & 1 deletion src/elements/dv-elements/utils/mixins/commons.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
};
}
convertToUnixPermissions(mode)
convertToUnixPermissions(mode, filetype)
{
const S_IRUSR = 0o0400; // owner has read permission
const S_IWUSR = 0o0200; // owner has write permission
Expand All @@ -43,6 +43,20 @@
const S_IFIFO = 0o010000; // Named pipe
const F_TYPE = 0o170000;

/**
* dCache doesn't have the file type in the mode flags, so
* allow this to be injected separately.
*/
if(filetype === "REGULAR") {
mode |= S_IFREG;
}
else if(filetype === "DIR") {
mode |= S_IFDIR;
}
else if(filetype === "LINK") {
mode |= S_IFLNK;
}

const modeChars = ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-',];
const type = mode & F_TYPE;

Expand Down

0 comments on commit 7ced9e6

Please sign in to comment.