From a81f7b1107d37a9b782582d16f619aa94d4577a7 Mon Sep 17 00:00:00 2001 From: zhangys36 Date: Fri, 12 Aug 2022 16:01:19 +0800 Subject: [PATCH] GUACAMOLE-1536: return file size and file permission information when uploading files and displaying file directories --- .../src/app/client/types/ManagedFilesystem.js | 91 +++++++++++++++++-- 1 file changed, 85 insertions(+), 6 deletions(-) diff --git a/guacamole/src/main/frontend/src/app/client/types/ManagedFilesystem.js b/guacamole/src/main/frontend/src/app/client/types/ManagedFilesystem.js index a81fcb1685..afd9f15f51 100644 --- a/guacamole/src/main/frontend/src/app/client/types/ManagedFilesystem.js +++ b/guacamole/src/main/frontend/src/app/client/types/ManagedFilesystem.js @@ -31,7 +31,7 @@ angular.module('client').factory('ManagedFilesystem', ['$rootScope', '$injector' * Object which serves as a surrogate interface, encapsulating a Guacamole * filesystem object while it is active, allowing it to be detached and * reattached from different client views. - * + * * @constructor * @param {ManagedFilesystem|Object} [template={}] * The object whose properties should be copied within the new @@ -147,13 +147,26 @@ angular.module('client').factory('ManagedFilesystem', ['$rootScope', '$injector' if (mimetypes[name] === Guacamole.Object.STREAM_INDEX_MIMETYPE) type = ManagedFilesystem.File.Type.DIRECTORY; + // try deserialization fileJSON String to fileObject + var size = 0; + var permission = null; + try { + var fileObj = JSON.parse(mimetypes[name]) + size = fileObj.size || 0; + if (fileObj.perm) { + permission = ManagedFilesystem.permissionTranslate(fileObj.perm); + } + } catch (e) { + return false; + } + // Add file entry file.files[filename] = new ManagedFilesystem.File({ - mimetype : mimetypes[name], - streamName : name, - type : type, - parent : file, - name : filename + mimetype: mimetypes[name], + streamName: name, + type: type, + parent: file, + name: filename }); } @@ -335,6 +348,72 @@ angular.module('client').factory('ManagedFilesystem', ['$rootScope', '$injector' }; + /** + * translate the permission number to the permission string + * + * @param {Number} permission + */ + ManagedFilesystem.permissionTranslate = function permissionTranslate(permission) { + + var Ow_R = 256; + var Ow_W = 128; + var Ow_X = 64; + var Gp_R = 32; + var Gp_W = 16; + var Gp_X = 8; + var Ot_R = 4; + var Ot_W = 2; + var Ot_X = 1; + + let res = ''; + if ((permission & Ow_R) === Ow_R) { + res += 'r'; + } else { + res += '-'; + } + if ((permission & Ow_W) === Ow_W) { + res += 'w'; + } else { + res += '-'; + } + if ((permission & Ow_X) === Ow_X) { + res += 'x'; + } else { + res += '-'; + } + if ((permission & Gp_R) === Gp_R) { + res += 'r'; + } else { + res += '-'; + } + if ((permission & Gp_W) === Gp_W) { + res += 'w'; + } else { + res += '-'; + } + if ((permission & Gp_X) === Gp_X) { + res += 'x'; + } else { + res += '-'; + } + if ((permission & Ot_R) === Ot_R) { + res += 'r'; + } else { + res += '-'; + } + if ((permission & Ot_W) === Ot_W) { + res += 'w'; + } else { + res += '-'; + } + if ((permission & Ot_X) === Ot_X) { + res += 'x'; + } else { + res += '-'; + } + return res; + } + return ManagedFilesystem; }]);