]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
regress: Add get_perm function to functions.pm module
authorEric Bollengier <eric@baculasystems.com>
Wed, 4 May 2022 08:11:50 +0000 (10:11 +0200)
committerEric Bollengier <eric@baculasystems.com>
Wed, 4 May 2022 08:11:50 +0000 (10:11 +0200)
Some tests are using "stat -c %a" to get file permission in
a way that is suitable to compare later on. Unfortunately,
it is not portable.

regress/scripts/functions.pm

index 9cc540ef92af7c2d48b71bfe3bc1694b2c8f6fd0..2154a985c201737bf16458d3a3047bcd929d2363 100644 (file)
@@ -52,7 +52,7 @@ our @EXPORT = qw(update_some_files create_many_files check_multiple_copies
                   check_openfile check_cloud_hash check_bscan add_log_message compare_backup_content
                   check_tls_traces println add_virtual_changer check_events check_events_json
                   create_many_hardlinks check_dot_status parse_fuse_trace generate_random_seek
-                  check_storage_selection check_json
+                  check_storage_selection check_json get_perm
 );
 
 
@@ -2575,4 +2575,12 @@ sub check_json
     }
     exit 0;
 }
+
+# Get the permission in octal for a file, equivalent to stat -c %a
+sub get_perm
+{
+    my ($file) = @_;
+    my $mode = (stat($file))[2];
+    printf "%04o\n", $mode & 07777;
+}
 1;