You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@guacamole.apache.org by GitBox <gi...@apache.org> on 2022/08/12 08:13:30 UTC

[GitHub] [guacamole-client] iamsee opened a new pull request, #754: GUACAMOLE-1536: return file size and file permission information when uploading files and displaying file directories

iamsee opened a new pull request, #754:
URL: https://github.com/apache/guacamole-client/pull/754

   https://github.com/apache/guacamole-server/pull/367


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [guacamole-client] mike-jumper commented on a diff in pull request #754: GUACAMOLE-1536: return file size and file permission information when uploading files and displaying file directories

Posted by GitBox <gi...@apache.org>.
mike-jumper commented on code in PR #754:
URL: https://github.com/apache/guacamole-client/pull/754#discussion_r959792046


##########
guacamole/src/main/frontend/src/app/client/types/ManagedFilesystem.js:
##########
@@ -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;

Review Comment:
   1. These should be defined (and documented) as constants: https://guacamole.apache.org/guac-style/#comments-and-documentation
   2. These should be named according to constant naming convention (`UPPERCASE_WITH_UNDERSCORES`): https://guacamole.apache.org/guac-style/#naming



##########
guacamole/src/main/frontend/src/app/client/types/ManagedFilesystem.js:
##########
@@ -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 += '-';
+        }

Review Comment:
   There's got to be a more readable way to do this. Perhaps you can structure things as a loop and avoid this kind of brute-force list?



##########
guacamole/src/main/frontend/src/app/client/types/ManagedFilesystem.js:
##########
@@ -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;

Review Comment:
   Why? `$evalAsync()` is not documented as doing anything with the return value of the provided callback.



##########
guacamole/src/main/frontend/src/app/client/types/ManagedFilesystem.js:
##########
@@ -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;
+                        }

Review Comment:
   Why? These values do not appear to be used anywhere.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@guacamole.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org