/[mldonkey]/mldonkey/src/utils/cdk/unix2.ml
ViewVC logotype

Diff of /mldonkey/src/utils/cdk/unix2.ml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.16 by spiralvoice, Thu Oct 6 17:34:22 2005 UTC revision 1.17 by spiralvoice, Mon Oct 17 15:25:46 2005 UTC
# Line 55  let is_link filename = Line 55  let is_link filename =
55    try let s = Unix.lstat filename in s.st_kind = S_LNK with _ -> false    try let s = Unix.lstat filename in s.st_kind = S_LNK with _ -> false
56    
57  let chmod f o =  let chmod f o =
58    try Unix.chmod f o with e -> lprintf "warning: chmod failed on %s: %s" f (Printexc2.to_string e)    try Unix.chmod f o with e -> lprintf_nl "warning: chmod failed on %s: %s" f (Printexc2.to_string e)
59    
60  let rec safe_mkdir dir =    let rec safe_mkdir dir =  
61    if Sys.file_exists dir then begin    if Sys.file_exists dir then begin
# Line 67  let rec safe_mkdir dir = Line 67  let rec safe_mkdir dir =
67      begin try      begin try
68        let dir = opendir dir in ()        let dir = opendir dir in ()
69        with        with
70          Unix.Unix_error (EACCES, _, _) -> lprintf "access denied for directory %s" dir; exit 73          Unix.Unix_error (EACCES, _, _) -> lprintf_nl "access denied for directory %s" dir; exit 73
71        | Unix.Unix_error (ENOENT, _, _) -> lprintf "directory %s not found, orphaned link?" dir; exit 73        | Unix.Unix_error (ENOENT, _, _) -> lprintf_nl "directory %s not found, orphaned link?" dir; exit 73
72        | e -> lprintf "error %s for directory %s" (Printexc2.to_string e) dir; exit 73        | e -> lprintf_nl "error %s for directory %s" (Printexc2.to_string e) dir; exit 73
73      end      end
74    else begin    else begin
75        let predir = Filename.dirname dir in        let predir = Filename.dirname dir in
# Line 113  let rename oldname newname = Line 113  let rename oldname newname =
113    try Unix.rename oldname newname with    try Unix.rename oldname newname with
114      Unix_error(EXDEV,_,_) as e ->      Unix_error(EXDEV,_,_) as e ->
115  (* renaming is not enough, we must COPY *)  (* renaming is not enough, we must COPY *)
116        lprintf "COPY %s TO %s\n" oldname newname;        lprintf_nl "COPY %s TO %s" oldname newname;
117        let copied = ref false in        let copied = ref false in
118        try        try
119          copy oldname newname;          copy oldname newname;
# Line 151  let random () = Line 151  let random () =
151    done;    done;
152    s    s
153    
154  let can_write_to_directory dirname =  let rec can_write_to_directory dirname =
155    let temp_file = Filename.concat dirname "tmp_" ^ random () ^ "_mld.tmp" in    let temp_file = Filename.concat dirname "tmp_" ^ random () ^ "_mld.tmp" in
156    try    try
157      (let oc = open_out_gen [Open_creat; Open_wronly; Open_append] 0o600 temp_file in      (let oc = open_out_gen [Open_creat; Open_wronly; Open_append] 0o600 temp_file in
# Line 160  let can_write_to_directory dirname = Line 160  let can_write_to_directory dirname =
160      (try Sys.remove temp_file with _ -> ())      (try Sys.remove temp_file with _ -> ())
161    with    with
162      Sys_error s when s = temp_file ^ ": " ^ (Unix.error_message Unix.EACCES) ->      Sys_error s when s = temp_file ^ ": " ^ (Unix.error_message Unix.EACCES) ->
163        lprintf "can not create files in directory %s, check rights..." dirname; exit 73        lprintf_nl "can not create files in directory %s, check rights..." dirname; exit 73
164    | Sys_error s -> lprintf "%s for directory %s" s dirname; exit 73    | Sys_error s when s = temp_file ^ ": " ^ (Unix.error_message Unix.ENOENT) ->
165    | e -> lprintf "%s for directory %s" (Printexc2.to_string e) dirname; exit 73        (try safe_mkdir dirname; can_write_to_directory dirname with _ ->
166            lprintf_nl "%s does not exist and can not be created, exiting..." dirname; exit 73)
167      | Sys_error s -> lprintf_nl "%s for directory %s" s dirname; exit 73
168      | e -> lprintf_nl "%s for directory %s" (Printexc2.to_string e) dirname; exit 73

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26