module file
intrude import stream
-intrude import string
+intrude import ropes
import string_search
import time
redef fun write(s)
do
assert _writable
- write_native(s.to_cstring, s.length)
+ if s isa FlatText then
+ write_native(s.to_cstring, s.length)
+ else
+ for i in s.substrings do write_native(i.to_cstring, i.length)
+ end
end
redef fun is_writable do return _writable
end
end
+ # Delete a directory and all of its content, return `true` on success
+ #
+ # Does not go through symbolic links and may get stuck in a cycle if there
+ # is a cycle in the filesystem.
+ fun rmdir: Bool
+ do
+ var ok = true
+ for file in self.files do
+ var file_path = self.join_path(file)
+ var stat = file_path.file_lstat
+ if stat.is_dir then
+ ok = file_path.rmdir and ok
+ else
+ ok = file_path.file_delete and ok
+ end
+ stat.free
+ end
+
+ # Delete the directory itself
+ if ok then to_cstring.rmdir
+
+ return ok
+ end
+
# Change the current working directory
#
# "/etc".chdir
return stat_element;
`}
private fun file_mkdir: Bool is extern "string_NativeString_NativeString_file_mkdir_0"
+ private fun rmdir: Bool `{ return rmdir(recv); `}
private fun file_delete: Bool is extern "string_NativeString_NativeString_file_delete_0"
private fun file_chdir is extern "string_NativeString_NativeString_file_chdir_0"
private fun file_realpath: NativeString is extern "file_NativeString_realpath"