178 |
178 |
179 |
179 |
180 |
180 |
181 /** file-system operations **/ |
181 /** file-system operations **/ |
182 |
182 |
|
183 /* scala functions */ |
|
184 |
|
185 private def apply_paths(arg: String, fun: List[Path] => Unit): String = |
|
186 { fun(Library.space_explode('\u0000', arg).map(Path.explode)); "" } |
|
187 |
|
188 private def apply_paths1(arg: String, fun: Path => Unit): String = |
|
189 apply_paths(arg, { case List(path) => fun(path) }) |
|
190 |
|
191 private def apply_paths2(arg: String, fun: (Path, Path) => Unit): String = |
|
192 apply_paths(arg, { case List(path1, path2) => fun(path1, path2) }) |
|
193 |
|
194 private def apply_paths3(arg: String, fun: (Path, Path, Path) => Unit): String = |
|
195 apply_paths(arg, { case List(path1, path2, path3) => fun(path1, path2, path3) }) |
|
196 |
|
197 |
183 /* permissions */ |
198 /* permissions */ |
184 |
199 |
185 def chmod(arg: String, path: Path): Unit = |
200 def chmod(arg: String, path: Path): Unit = |
186 bash("chmod " + arg + " " + File.bash_path(path)).check |
201 bash("chmod " + arg + " " + File.bash_path(path)).check |
187 |
202 |
196 try { Files.createDirectories(path.file.toPath) } |
211 try { Files.createDirectories(path.file.toPath) } |
197 catch { case ERROR(_) => error("Failed to create directory: " + path.absolute) } |
212 catch { case ERROR(_) => error("Failed to create directory: " + path.absolute) } |
198 path |
213 path |
199 } |
214 } |
200 |
215 |
201 object Make_Directory extends Scala.Fun("make_directory") |
|
202 { |
|
203 val here = Scala_Project.here |
|
204 def apply(arg: String): String = { make_directory(Path.explode(arg)); "" } |
|
205 } |
|
206 |
|
207 def new_directory(path: Path): Path = |
216 def new_directory(path: Path): Path = |
208 if (path.is_dir) error("Directory already exists: " + path.absolute) |
217 if (path.is_dir) error("Directory already exists: " + path.absolute) |
209 else make_directory(path) |
218 else make_directory(path) |
210 |
219 |
211 |
|
212 |
|
213 /* copy */ |
|
214 |
|
215 def copy_dir(dir1: Path, dir2: Path): Unit = |
220 def copy_dir(dir1: Path, dir2: Path): Unit = |
216 bash("cp -a " + File.bash_path(dir1) + " " + File.bash_path(dir2)).check |
221 { |
|
222 val res = bash("cp -a " + File.bash_path(dir1) + " " + File.bash_path(dir2)) |
|
223 if (!res.ok) { |
|
224 cat_error("Failed to copy directory " + dir1.absolute + " to " + dir2.absolute, res.err) |
|
225 } |
|
226 } |
|
227 |
|
228 |
|
229 object Make_Directory extends Scala.Fun("make_directory") |
|
230 { |
|
231 val here = Scala_Project.here |
|
232 def apply(arg: String): String = apply_paths1(arg, make_directory) |
|
233 } |
|
234 |
|
235 object Copy_Dir extends Scala.Fun("copy_dir") |
|
236 { |
|
237 val here = Scala_Project.here |
|
238 def apply(arg: String): String = apply_paths2(arg, copy_dir) |
|
239 } |
|
240 |
|
241 |
|
242 /* copy files */ |
217 |
243 |
218 def copy_file(src: JFile, dst: JFile): Unit = |
244 def copy_file(src: JFile, dst: JFile): Unit = |
219 { |
245 { |
220 val target = if (dst.isDirectory) new JFile(dst, src.getName) else dst |
246 val target = if (dst.isDirectory) new JFile(dst, src.getName) else dst |
221 if (!File.eq(src, target)) { |
247 if (!File.eq(src, target)) { |
222 Files.copy(src.toPath, target.toPath, |
248 try { |
223 StandardCopyOption.COPY_ATTRIBUTES, |
249 Files.copy(src.toPath, target.toPath, |
224 StandardCopyOption.REPLACE_EXISTING) |
250 StandardCopyOption.COPY_ATTRIBUTES, |
|
251 StandardCopyOption.REPLACE_EXISTING) |
|
252 } |
|
253 catch { |
|
254 case ERROR(msg) => |
|
255 cat_error("Failed top copy file " + |
|
256 File.path(src).absolute + " to " + File.path(dst).absolute, msg) |
|
257 } |
225 } |
258 } |
226 } |
259 } |
227 |
260 |
228 def copy_file(src: Path, dst: Path): Unit = copy_file(src.file, dst.file) |
261 def copy_file(src: Path, dst: Path): Unit = copy_file(src.file, dst.file) |
229 |
262 |
234 if (!src1.starts_basic) error("Illegal path specification " + src1 + " beyond base directory") |
267 if (!src1.starts_basic) error("Illegal path specification " + src1 + " beyond base directory") |
235 copy_file(base_dir + src1, Isabelle_System.make_directory(target_dir + src1_dir)) |
268 copy_file(base_dir + src1, Isabelle_System.make_directory(target_dir + src1_dir)) |
236 } |
269 } |
237 |
270 |
238 |
271 |
239 /* move */ |
272 object Copy_File extends Scala.Fun("copy_file") |
|
273 { |
|
274 val here = Scala_Project.here |
|
275 def apply(arg: String): String = apply_paths2(arg, copy_file) |
|
276 } |
|
277 |
|
278 object Copy_File_Base extends Scala.Fun("copy_file_base") |
|
279 { |
|
280 val here = Scala_Project.here |
|
281 def apply(arg: String): String = apply_paths3(arg, copy_file_base) |
|
282 } |
|
283 |
|
284 |
|
285 /* move files */ |
240 |
286 |
241 def move_file(src: JFile, dst: JFile) |
287 def move_file(src: JFile, dst: JFile) |
242 { |
288 { |
243 val target = if (dst.isDirectory) new JFile(dst, src.getName) else dst |
289 val target = if (dst.isDirectory) new JFile(dst, src.getName) else dst |
244 if (!File.eq(src, target)) |
290 if (!File.eq(src, target)) |