Added WSF_FILE_UTILITIES.new_file (p: PATH): detachable G
in order to provide non existing file, but not only for temporary files purpose.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
note
|
||||
description: "[
|
||||
This class is used to get a safe temporary file
|
||||
in a specific directory, for an optional prefix, and an optional expected filename.
|
||||
Collection of file system utilities.
|
||||
|
||||
Such as getting safe temporary file in a specific directory,
|
||||
for an optional prefix, and an optional expected filename.
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
@@ -11,19 +13,42 @@ class
|
||||
|
||||
feature -- Factory
|
||||
|
||||
new_file (p: PATH): detachable G
|
||||
-- New temporary file open for writing at location `p' or appended with integer suffix if already exists.
|
||||
local
|
||||
f: G
|
||||
bn: STRING_32
|
||||
n: INTEGER
|
||||
do
|
||||
from
|
||||
create f.make_with_path (p)
|
||||
Result := new_file_opened_for_writing (f)
|
||||
n := 0
|
||||
until
|
||||
Result /= Void
|
||||
or else n > 1_000
|
||||
loop
|
||||
n := n + 1
|
||||
create bn.make (2 + n // 10)
|
||||
bn.append_character ('-')
|
||||
bn.append_integer (n)
|
||||
f.make_with_path (p.appended (bn))
|
||||
Result := new_file_opened_for_writing (f)
|
||||
end
|
||||
ensure
|
||||
result_opened_for_writing_if_set: Result /= Void implies Result.is_open_write
|
||||
end
|
||||
|
||||
new_temporary_file (d: DIRECTORY; a_prefix: detachable READABLE_STRING_GENERAL; a_name: detachable READABLE_STRING_GENERAL): detachable G
|
||||
-- New temporary file open for writing inside directory `d', with prefix `a_prefix' is set, and based on name `a_name' is set.
|
||||
-- If it is unable to create such file opened for writing, then return Void.
|
||||
require
|
||||
d_valid: d.exists and then d.is_writable
|
||||
local
|
||||
f: G
|
||||
fn: PATH
|
||||
bn, tmp: STRING_32
|
||||
tmp: STRING_32
|
||||
dn: PATH
|
||||
n: INTEGER
|
||||
do
|
||||
from
|
||||
if a_prefix /= Void then
|
||||
create tmp.make_from_string_general (a_prefix)
|
||||
else
|
||||
@@ -36,21 +61,7 @@ feature -- Factory
|
||||
end
|
||||
|
||||
fn := dn.extended (tmp)
|
||||
create f.make_with_path (fn)
|
||||
Result := new_file_opened_for_writing (f)
|
||||
n := 0
|
||||
until
|
||||
Result /= Void
|
||||
or else n > 1_000
|
||||
loop
|
||||
n := n + 1
|
||||
create bn.make_from_string (tmp)
|
||||
bn.append_character ('-')
|
||||
bn.append_integer (n)
|
||||
fn := dn.extended (bn)
|
||||
f.make_with_path (fn)
|
||||
Result := new_file_opened_for_writing (f)
|
||||
end
|
||||
Result := new_file (fn)
|
||||
ensure
|
||||
result_opened_for_writing_if_set: Result /= Void implies Result.is_open_write
|
||||
end
|
||||
@@ -162,7 +173,7 @@ feature {NONE} -- Implementation
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2014, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
|
||||
Reference in New Issue
Block a user