Mercurial Hosting > luan
comparison src/luan/modules/IoLuan.java @ 1367:836e00bf7ce2
add Lucene backup_to
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 18 Jun 2019 16:27:03 -0600 |
parents | 0cceff521abb |
children | b765f146f4dc |
comparison
equal
deleted
inserted
replaced
1366:ae2321a09723 | 1367:836e00bf7ce2 |
---|---|
132 } | 132 } |
133 }; | 133 }; |
134 } | 134 } |
135 | 135 |
136 | 136 |
137 private static File objToFile(Object obj) { | 137 private static File objToFile(Luan luan,Object obj) throws LuanException { |
138 if( obj instanceof String ) { | 138 if( obj instanceof String ) { |
139 return new File((String)obj); | 139 String fileName = (String)obj; |
140 check(luan,"file:"+fileName); | |
141 return new File(fileName); | |
140 } | 142 } |
141 if( obj instanceof LuanTable ) { | 143 if( obj instanceof LuanTable ) { |
142 LuanTable t = (LuanTable)obj; | 144 LuanTable t = (LuanTable)obj; |
143 Object java = t.rawGet("java"); | 145 Object java = t.rawGet("java"); |
144 if( java instanceof LuanFile ) { | 146 if( java instanceof LuanFile ) { |
442 | 444 |
443 @Override public boolean exists() { | 445 @Override public boolean exists() { |
444 return file.exists(); | 446 return file.exists(); |
445 } | 447 } |
446 | 448 |
447 public void rename_to(Object destObj) throws LuanException { | 449 public void rename_to(Luan luan,Object destObj) throws LuanException { |
448 File dest = objToFile(destObj); | 450 File dest = objToFile(luan,destObj); |
449 if( dest==null ) | 451 if( dest==null ) |
450 throw new LuanException( "bad argument #1 to 'objToFile' (string or file table expected)" ); | 452 throw new LuanException( "bad argument #1 to 'rename_to' (string or file table expected)" ); |
451 if( !file.renameTo(dest) ) | 453 if( !file.renameTo(dest) ) |
452 throw new LuanException("couldn't rename file "+file+" to "+dest); | 454 throw new LuanException("couldn't rename file "+file+" to "+dest); |
455 } | |
456 | |
457 public void link_to(Luan luan,Object destObj) throws LuanException, IOException { | |
458 File dest = objToFile(luan,destObj); | |
459 if( dest==null ) | |
460 throw new LuanException( "bad argument #1 to 'link_to' (string or file table expected)" ); | |
461 Files.createLink( file.toPath(), dest.toPath() ); | |
462 } | |
463 | |
464 public void symlink_to(Luan luan,Object destObj) throws LuanException, IOException { | |
465 File dest = objToFile(luan,destObj); | |
466 if( dest==null ) | |
467 throw new LuanException( "bad argument #1 to 'symlink_to' (string or file table expected)" ); | |
468 Files.createSymbolicLink( file.toPath(), dest.toPath() ); | |
453 } | 469 } |
454 | 470 |
455 public LuanFile canonical(Luan luan) throws LuanException, IOException { | 471 public LuanFile canonical(Luan luan) throws LuanException, IOException { |
456 return new LuanFile(luan,file.getCanonicalFile()); | 472 return new LuanFile(luan,file.getCanonicalFile()); |
457 } | 473 } |
533 public static class BaseOs extends LuanIO { | 549 public static class BaseOs extends LuanIO { |
534 private final String cmd; | 550 private final String cmd; |
535 final File dir; | 551 final File dir; |
536 Process proc; | 552 Process proc; |
537 | 553 |
538 private BaseOs(String cmd,LuanTable options) throws IOException, LuanException { | 554 private BaseOs(Luan luan,String cmd,LuanTable options) throws IOException, LuanException { |
539 this.cmd = cmd; | 555 this.cmd = cmd; |
540 File dir = null; | 556 File dir = null; |
541 if( options != null ) { | 557 if( options != null ) { |
542 Map map = options.asMap(); | 558 Map map = options.asMap(); |
543 Object obj = map.remove("dir"); | 559 Object obj = map.remove("dir"); |
544 dir = objToFile(obj); | 560 dir = objToFile(luan,obj); |
545 if( dir==null ) | 561 if( dir==null ) |
546 throw new LuanException( "bad option 'dir' (string or file table expected)" ); | 562 throw new LuanException( "bad option 'dir' (string or file table expected)" ); |
547 if( !map.isEmpty() ) | 563 if( !map.isEmpty() ) |
548 throw new LuanException( "unrecognized options: "+map ); | 564 throw new LuanException( "unrecognized options: "+map ); |
549 } | 565 } |
594 } | 610 } |
595 } | 611 } |
596 | 612 |
597 public static final class LuanOs extends BaseOs { | 613 public static final class LuanOs extends BaseOs { |
598 public LuanOs(Luan luan,String cmd,LuanTable options) throws IOException, LuanException { | 614 public LuanOs(Luan luan,String cmd,LuanTable options) throws IOException, LuanException { |
599 super(cmd,options); | 615 super(luan,cmd,options); |
600 check(luan,"os:"+cmd); | 616 check(luan,"os:"+cmd); |
601 this.proc = Runtime.getRuntime().exec(cmd,null,dir); | 617 this.proc = Runtime.getRuntime().exec(cmd,null,dir); |
602 } | 618 } |
603 } | 619 } |
604 | 620 |
605 public static final class LuanBash extends BaseOs { | 621 public static final class LuanBash extends BaseOs { |
606 public LuanBash(Luan luan,String cmd,LuanTable options) throws IOException, LuanException { | 622 public LuanBash(Luan luan,String cmd,LuanTable options) throws IOException, LuanException { |
607 super(cmd,options); | 623 super(luan,cmd,options); |
608 check(luan,"bash:"+cmd); | 624 check(luan,"bash:"+cmd); |
609 this.proc = Runtime.getRuntime().exec(new String[]{"bash","-c",cmd},null,dir); | 625 this.proc = Runtime.getRuntime().exec(new String[]{"bash","-c",cmd},null,dir); |
610 } | 626 } |
611 } | 627 } |
612 | 628 |