#line 494 "/home/ubuntu/felix/src/packages/filesystem.fdoc"
class FileSystem_class[os]
{
}
class FileSystem {
if PLAT_WIN32 do
inherit Win32FileSystem;
else
inherit PosixFileSystem;
done
proc unlink(f:string)
{
proc aux (d:string) (b:string)
{
if b == "." or b == ".." return;
var f = if d == "" then b else Filename::join (d,b);
match FileStat::filetype f with
| #PIPE => ;
| #STREAM => ;
| #DIRECTORY =>
match Directory::filesin f with
| #None => ;
| Some files =>
for file in files do
aux f file;
done
C_hack::ignore$ Directory::unlink_empty_dir f;
endmatch;
| #BLOCK => ;
| #REGULAR => C_hack::ignore$ unlink_file f;
| #SYMLINK => C_hack::ignore$ unlink_file f;
| #SOCKET => ;
| #INDETERMINATE => ;
| #NONEXISTANT => ;
| #NOPERMISSION => ;
endmatch;
}
aux "" f;
}
proc rm (f:string) => unlink f;
fun find_in_path(x:string, path:list[string]):opt[string]=>
match path with
| #Empty => None[string]
| Cons (d,t) =>
let p = Filename::join(d,x) in
match FileStat::fileexists p with
| true => Some p
| false => find_in_path (x,t)
endmatch
endmatch
;
fun regfilesin(dname:string, re:string): list[string] => regfilesin(dname, Re2::RE2 re);
fun regfilesin(dname:string, re:RE2): list[string] = {
var foundfiles = Empty[string];
proc rfi(dname2: string) {
if dname2 == "." or dname2 == ".." return;
var newpath = if dname2 == "" then dname else Filename::join (dname,dname2);
var newfiles = Directory::filesin(newpath);
match newfiles with
| #None => return;
| Some files =>
for f in files do
if f == "." or f == ".." do ;
else
var d = Filename::join (dname2,f);
var fullpath = Filename::join (dname,d);
var t = FileStat::filetype fullpath;
match t with
| #REGULAR =>
var result = d in re;
if result do
foundfiles = Cons (d, foundfiles);
done
| #DIRECTORY =>
rfi (d);
| _ => ;
endmatch;
done
done
endmatch;
}
rfi ("");
return rev foundfiles;
}
}