X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=utils.ml;h=b06a127d87e8be23edc2a25d3ab79935e6c2ac1c;hb=HEAD;hp=e3e99199afa30cb9b02c93712dd785d06c1f75f6;hpb=674ec31578216d728c4ab9c0a8a297e47c81c492;p=guestfs-browser.git diff --git a/utils.ml b/utils.ml index e3e9919..b06a127 100644 --- a/utils.ml +++ b/utils.ml @@ -25,6 +25,7 @@ let (+^) = Int64.add let (-^) = Int64.sub let ( *^ ) = Int64.mul let (/^) = Int64.div +let (&^) = Int64.logand type ('a, 'b) either = Left of 'a | Right of 'b @@ -62,6 +63,7 @@ let connect_uri = ref None let set_connect_uri conn = connect_uri := conn let connect_uri () = !connect_uri +let utf8_copyright = "\194\169" let utf8_rarrow = "\xe2\x86\x92" let pretty_string_of_exn = @@ -76,11 +78,25 @@ To get more information about libguestfs errors, run guestfs-browser with the -x flag on the command line." str + | Libvirt.Virterror err -> + "Libvirt error", + sprintf "libvirt reported an error: + +%s + +To get more information about libvirt errors, run guestfs-browser +from the command line like this: + +LIBVIRT_DEBUG=1 guestfs-browser" + (Libvirt.Virterror.to_string err) + (* Add more exception types here as we come across them. Last * case below is the catch-all. *) | exn -> - "Error", Printexc.to_string exn + let str = Printexc.to_string exn in + debug "pretty_string_of_exn: unhandled exception %s" str; + "Error", str let human_size i = if i < 1024L then @@ -163,16 +179,47 @@ and is_xo mode = test_bit 0o001L mode and test_bit mask mode = Int64.logand mode mask = mask +let file_permissions_string mode = + let c = + if is_socket mode then 's' + else if is_symlink mode then 'l' + else if is_regular_file mode then '-' + else if is_block mode then 'b' + else if is_directory mode then 'd' + else if is_char mode then 'c' + else if is_fifo mode then 'p' else '?' in + let ru = if is_ru mode then 'r' else '-' in + let wu = if is_wu mode then 'w' else '-' in + let xu = if is_xu mode then 'x' else '-' in + let rg = if is_rg mode then 'r' else '-' in + let wg = if is_wg mode then 'w' else '-' in + let xg = if is_xg mode then 'x' else '-' in + let ro = if is_ro mode then 'r' else '-' in + let wo = if is_wo mode then 'w' else '-' in + let xo = if is_xo mode then 'x' else '-' in + let str = sprintf "%c%c%c%c%c%c%c%c%c%c" c ru wu xu rg wg xg ro wo xo in + + let suid = is_suid mode in + let sgid = is_sgid mode in + let svtx = is_svtx mode in + let str = Bytes.of_string str in + if suid then Bytes.set str 3 's'; + if sgid then Bytes.set str 6 's'; + if svtx then Bytes.set str 9 't'; + + Bytes.to_string str + let tmpdir () = let chan = open_in "/dev/urandom" in - let data = String.create 16 in - really_input chan data 0 (String.length data); + let data = Bytes.create 16 in + really_input chan data 0 (Bytes.length data); close_in chan; - let data = Digest.to_hex (Digest.string data) in + let data = Digest.to_hex (Digest.bytes data) in (* Note this is secure, because if the name already exists, even as a * symlink, mkdir(2) will fail. *) - let tmpdir = Filename.temp_dir_name // sprintf "guestfsbrowser%s.tmp" data in + let tmpdir = + Filename.get_temp_dir_name () // sprintf "guestfsbrowser%s.tmp" data in Unix.mkdir tmpdir 0o700; at_exit (fun () ->