Blame src/FileUtilPermission.ml

Packit 9ff65e
(******************************************************************************)
Packit 9ff65e
(*  ocaml-fileutils: files and filenames common operations                    *)
Packit 9ff65e
(*                                                                            *)
Packit 9ff65e
(*  Copyright (C) 2003-2014, Sylvain Le Gall                                  *)
Packit 9ff65e
(*                                                                            *)
Packit 9ff65e
(*  This library is free software; you can redistribute it and/or modify it   *)
Packit 9ff65e
(*  under the terms of the GNU Lesser General Public License as published by  *)
Packit 9ff65e
(*  the Free Software Foundation; either version 2.1 of the License, or (at   *)
Packit 9ff65e
(*  your option) any later version, with the OCaml static compilation         *)
Packit 9ff65e
(*  exception.                                                                *)
Packit 9ff65e
(*                                                                            *)
Packit 9ff65e
(*  This library is distributed in the hope that it will be useful, but       *)
Packit 9ff65e
(*  WITHOUT ANY WARRANTY; without even the implied warranty of                *)
Packit 9ff65e
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file         *)
Packit 9ff65e
(*  COPYING for more details.                                                 *)
Packit 9ff65e
(*                                                                            *)
Packit 9ff65e
(*  You should have received a copy of the GNU Lesser General Public License  *)
Packit 9ff65e
(*  along with this library; if not, write to the Free Software Foundation,   *)
Packit 9ff65e
(*  Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA             *)
Packit 9ff65e
(******************************************************************************)
Packit 9ff65e
Packit 9ff65e
open FileUtilTypes
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
let permission_of_int pr =
Packit 9ff65e
  let perm_match oct =
Packit 9ff65e
    (pr land oct) <> 0
Packit 9ff65e
  in
Packit 9ff65e
  {
Packit 9ff65e
    user =
Packit 9ff65e
      {
Packit 9ff65e
        sticky = perm_match 0o4000;
Packit 9ff65e
        exec   = perm_match 0o0100;
Packit 9ff65e
        write  = perm_match 0o0200;
Packit 9ff65e
        read   = perm_match 0o0400;
Packit 9ff65e
      };
Packit 9ff65e
    group =
Packit 9ff65e
      {
Packit 9ff65e
        sticky = perm_match 0o2000;
Packit 9ff65e
        exec   = perm_match 0o0010;
Packit 9ff65e
        write  = perm_match 0o0020;
Packit 9ff65e
        read   = perm_match 0o0040;
Packit 9ff65e
      };
Packit 9ff65e
    other =
Packit 9ff65e
      {
Packit 9ff65e
        sticky = perm_match 0o1000;
Packit 9ff65e
        exec   = perm_match 0o0001;
Packit 9ff65e
        write  = perm_match 0o0002;
Packit 9ff65e
        read   = perm_match 0o0004;
Packit 9ff65e
      };
Packit 9ff65e
  }
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
let int_of_permission pr =
Packit 9ff65e
  let permission_int = [
Packit 9ff65e
    (pr.user.sticky,  0o4000);
Packit 9ff65e
    (pr.user.exec,    0o0100);
Packit 9ff65e
    (pr.user.write,   0o0200);
Packit 9ff65e
    (pr.user.read,    0o0400);
Packit 9ff65e
    (pr.group.sticky, 0o2000);
Packit 9ff65e
    (pr.group.exec,   0o0010);
Packit 9ff65e
    (pr.group.write,  0o0020);
Packit 9ff65e
    (pr.group.read,   0o0040);
Packit 9ff65e
    (pr.other.sticky, 0o1000);
Packit 9ff65e
    (pr.other.exec,   0o0001);
Packit 9ff65e
    (pr.other.write,  0o0002);
Packit 9ff65e
    (pr.other.read,   0o0004)
Packit 9ff65e
  ]
Packit 9ff65e
  in
Packit 9ff65e
  List.fold_left (fun full_perm (b, perm) ->
Packit 9ff65e
    if b then
Packit 9ff65e
      perm lor full_perm
Packit 9ff65e
    else
Packit 9ff65e
      full_perm)
Packit 9ff65e
    0o0000 permission_int