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 |
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 |
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; |
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 |
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 |