(JSONArray args, CallbackContext callback)
| 483 | } |
| 484 | |
| 485 | public void stat(JSONArray args, CallbackContext callback) { |
| 486 | cordova |
| 487 | .getThreadPool() |
| 488 | .execute( |
| 489 | new Runnable() { |
| 490 | public void run() { |
| 491 | try { |
| 492 | String path = sanitizePath(args.optString(0)); |
| 493 | if (ssh != null && sftp != null) { |
| 494 | URI uri = new URI(path); |
| 495 | JSONObject fileStat = new JSONObject(); |
| 496 | |
| 497 | try { |
| 498 | SftpFileAttributes fileAttributes = sftp.stat(uri.getPath()); |
| 499 | if (fileAttributes != null) { |
| 500 | String permissions = fileAttributes.toPermissionsString(); |
| 501 | boolean canRead = permissions.charAt(1) == 'r'; |
| 502 | boolean canWrite = permissions.charAt(2) == 'w'; |
| 503 | |
| 504 | fileStat.put("exists", true); |
| 505 | fileStat.put("canRead", canRead); |
| 506 | fileStat.put("canWrite", canWrite); |
| 507 | fileStat.put("isLink", fileAttributes.isLink()); |
| 508 | fileStat.put("isDirectory", fileAttributes.isDirectory()); |
| 509 | fileStat.put("isFile", fileAttributes.isFile()); |
| 510 | fileStat.put("length", fileAttributes.size()); |
| 511 | fileStat.put( |
| 512 | "permissions", |
| 513 | fileAttributes.toPermissionsString() |
| 514 | ); |
| 515 | fileStat.put( |
| 516 | "lastModified", |
| 517 | fileAttributes.lastModifiedTime() |
| 518 | ); |
| 519 | String[] pathSegments = uri.getPath().split("/"); |
| 520 | String filename = pathSegments[pathSegments.length - 1]; |
| 521 | |
| 522 | fileStat.put("name", filename); |
| 523 | fileStat.put("url", uri.getPath()); |
| 524 | if (permissions.charAt(0) == 'l') { |
| 525 | fileStat.put("isLink", true); |
| 526 | try { |
| 527 | String linkTarget = sftp.getSymbolicLinkTarget( |
| 528 | uri.getPath() |
| 529 | ); |
| 530 | fileStat.put("linkTarget", linkTarget); |
| 531 | SftpFileAttributes linkAttributes = sftp.stat( |
| 532 | linkTarget |
| 533 | ); |
| 534 | fileStat.put("isFile", linkAttributes.isFile()); |
| 535 | fileStat.put( |
| 536 | "isDirectory", |
| 537 | linkAttributes.isDirectory() |
| 538 | ); |
| 539 | } catch (SftpStatusException | SshException e) { |
| 540 | // Handle broken symlink |
| 541 | fileStat.put("isFile", false); |
| 542 | fileStat.put("isDirectory", false); |
no test coverage detected