PageRenderTime 14ms CodeModel.GetById 8ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/src/lib/io/filesystem/directory_notation.e

http://github.com/tybor/Liberty
Specman e | 265 lines | 162 code | 23 blank | 80 comment | 7 complexity | 8fceaad266564ab99b685b236a2e0402 MD5 | raw file
  1-- This file is part of a Liberty Eiffel library.
  2-- See the full copyright at the end.
  3--
  4deferred class DIRECTORY_NOTATION
  5
  6feature {ANY}
  7   is_current_directory (path: STRING): BOOLEAN
  8      deferred
  9      end
 10
 11   is_parent_directory (path: STRING): BOOLEAN
 12      deferred
 13      end
 14
 15   to_parent_directory (some_path: STRING)
 16         -- Tries to compute in `some_path' (which may be either a
 17         -- file path or a directory path) the parent directory of
 18         -- `some_path'. When `some_path' is a path with no parent
 19         -- directory, `some_path' `is_empty' after this call. This
 20         -- operation does not perform any disk access.
 21      require
 22         is_valid_path(some_path)
 23      deferred
 24      end
 25
 26   to_subdirectory_with (parent_path, entry_name: STRING)
 27         -- Try to compute in `parent_path' the new subdirectory path
 28         -- obtained when trying to concatenate smartly `parent_path'
 29         -- with some `entry_name'. When this fails, `parent_path'
 30         -- `is_empty' after this call. This operation does not
 31         -- perform any disk access.
 32      require
 33         is_valid_path(parent_path)
 34         is_valid_path(entry_name)
 35      deferred
 36      ensure
 37         entry_name.is_equal(old entry_name.twin)
 38      end
 39
 40   to_file_path_with (parent_path, file_name: STRING)
 41         -- Try to compute in `parent_path' the new file path obtained
 42         -- when trying to concatenate smartly `parent_path' with
 43         -- some `file_name'. When this fails, `parent_path'
 44         -- `is_empty' after this call. This operation does not
 45         -- perform any disk access.
 46      require
 47         is_valid_path(parent_path)
 48         is_valid_file_name(file_name)
 49      deferred
 50      ensure
 51         file_name.is_equal(old file_name.twin)
 52      end
 53
 54   to_subpath_with (parent_path, subpath: STRING)
 55         -- Try to compute in `parent_path' the new file path obtained
 56         -- when trying to concatenate smartly `parent_path' with
 57         -- some `subpath'. When this fails, `parent_path'
 58         -- `is_empty' after this call. This operation does not
 59         -- perform any disk access.
 60      require
 61         is_valid_directory_path(parent_path)
 62         is_valid_path(subpath)
 63         not is_absolute_path(subpath)
 64      deferred
 65      ensure
 66         parent_path.is_empty or else is_valid_path(parent_path)
 67         parent_path.is_empty or else is_valid_directory_path(parent_path) = old is_valid_directory_path(subpath)
 68         parent_path.is_empty or else is_absolute_path(parent_path) = old is_absolute_path(parent_path)
 69      end
 70
 71   frozen to_absolute_path_in (possible_parent, path: STRING)
 72         -- If `path' is not absolute, make it so by appending it to
 73         -- `possible_parent'. Else, overwrite `possible_parent' with
 74         -- path.
 75      require
 76         is_valid_directory_path(possible_parent)
 77         is_absolute_path(possible_parent)
 78         is_valid_path(path)
 79      do
 80         if not is_absolute_path(path) then
 81            to_subpath_with(possible_parent, path)
 82         else
 83            possible_parent.copy(path)
 84         end
 85      ensure
 86         is_absolute_path(possible_parent)
 87      end
 88
 89   to_short_name_in (buffer, path: STRING)
 90      require
 91         is_valid_path(path)
 92         buffer /= Void
 93      deferred
 94      end
 95
 96feature {ANY}
 97   frozen from_notation (source_notation: DIRECTORY_NOTATION; path: STRING)
 98         -- Convert `path' from `source_notation' to `Current'
 99         -- notation. If this fails, then `path' `is_empty' after this
100         -- call.
101      require
102         source_notation.is_valid_path(path)
103      local
104         tmp: STRING
105      do
106         tmp := source_notation.to_notation(path, Current)
107         if path /= tmp then
108            path.copy(tmp)
109         end
110      ensure
111         path.is_empty or else is_valid_path(path)
112      end
113
114   can_sanitize (name: STRING): BOOLEAN
115      do
116         -- Default is to have no sanitizing
117      end
118
119   to_valid_file_name (name: STRING)
120         -- Sanitize `name' (by removing forbidden characters or
121         -- encoding them)
122      require
123         name /= Void
124         not is_valid_file_name(name)
125         can_sanitize(name)
126      do
127         check
128            False
129         end
130      ensure
131         is_valid_file_name(name)
132      end
133
134   to_directory_path (path: STRING)
135         -- Make sure that the given path is a canonical directory
136         -- path as would be returned by `to_subdirectory_with'
137      require
138         path /= Void
139         is_valid_path(path)
140      deferred
141      ensure
142         is_valid_directory_path(path)
143      end
144
145   can_map_drive (source_notation: DIRECTORY_NOTATION; drive: STRING): BOOLEAN
146      deferred
147      end
148
149   to_root (source_notation: DIRECTORY_NOTATION; drive: STRING)
150         -- Convert `drive' from a drive letter/device name in
151         -- `source_notation' to an absolute path in `Current'
152         -- notation.
153      require
154         can_map_drive(source_notation, drive)
155      deferred
156      ensure
157         is_valid_path(drive)
158         is_absolute_path(drive)
159      end
160
161   to_default_root (directory: STRING)
162      deferred
163      ensure
164         is_valid_path(directory)
165         is_absolute_path(directory)
166      end
167
168   to_current_directory (directory: STRING)
169         -- Put the relative directory representing the current
170         -- working directory into directory. Not to be confused with
171         -- the absolute path of the current working directory at a
172         -- given time. This operation does not perform any disk
173         -- access.
174      require
175         directory /= Void
176      deferred
177      ensure
178         is_valid_path(directory)
179         not is_absolute_path(directory)
180      end
181
182feature {ANY}
183   is_case_sensitive: BOOLEAN
184      deferred
185      end
186
187   is_valid_path (path: STRING): BOOLEAN
188         -- Does `path' represent a syntactically valid file or
189         -- directory path? The result does not imply that there
190         -- actually a file or directory with that name. This
191         -- operation does not perform any disk access.
192      deferred
193      ensure
194         path.is_equal(old path.twin)
195         Result implies not path.is_empty
196      end
197
198   is_valid_directory_path (path: STRING): BOOLEAN
199         -- Does `path' represent a syntactically valid directory
200         -- path? For many Systems, there may be no syntactical
201         -- difference between file paths and directory paths, in
202         -- that case there is no difference between
203         -- `is_valid_directory_path' and `is_valid_path'.
204      deferred
205      ensure
206         path.is_equal(old path.twin)
207         Result implies is_valid_path(path)
208      end
209
210   is_valid_file_name (name: STRING): BOOLEAN
211         -- Does `path' only contain valid characters for a file? The
212         -- result does not imply that there is actually a file or
213         -- directory with that name. Not the same as `is_valid_path':
214         -- path separators (/ for unix, \ for windows, ...) are
215         -- allowed in paths, but not in file names. This operation
216         -- does not perform any disk access.
217      deferred
218      ensure
219         name.is_equal(old name.twin)
220         Result implies not name.is_empty
221      end
222
223   is_absolute_path (path: STRING): BOOLEAN
224         -- Is `path' absolute, i.e. is its meaning independent of
225         -- current drive and working directory ? This operation does
226         -- not perform any disk access.
227      require
228         is_valid_path(path)
229      deferred
230      ensure
231         path.is_equal(old path.twin)
232      end
233
234feature {DIRECTORY_NOTATION}
235   to_notation (path: STRING; destination_notation: DIRECTORY_NOTATION): STRING
236      require
237         is_valid_path(path)
238         destination_notation /= Void
239      deferred
240      ensure
241         path.is_equal(old path.twin)
242         Result.is_empty or else destination_notation.is_valid_path(Result)
243      end
244
245end -- class DIRECTORY_NOTATION
246--
247-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
248--
249-- Permission is hereby granted, free of charge, to any person obtaining a copy
250-- of this software and associated documentation files (the "Software"), to deal
251-- in the Software without restriction, including without limitation the rights
252-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
253-- copies of the Software, and to permit persons to whom the Software is
254-- furnished to do so, subject to the following conditions:
255--
256-- The above copyright notice and this permission notice shall be included in
257-- all copies or substantial portions of the Software.
258--
259-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
260-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
261-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
262-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
263-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
264-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
265-- THE SOFTWARE.