(JSONArray args, CallbackContext callback)
| 407 | } |
| 408 | |
| 409 | public void lsDir(JSONArray args, CallbackContext callback) { |
| 410 | cordova |
| 411 | .getThreadPool() |
| 412 | .execute( |
| 413 | new Runnable() { |
| 414 | public void run() { |
| 415 | try { |
| 416 | String path = args.optString(0); |
| 417 | if (ssh != null && sftp != null) { |
| 418 | JSONArray files = new JSONArray(); |
| 419 | for (SftpFile file : sftp.ls(path)) { |
| 420 | String filename = file.getFilename(); |
| 421 | if (filename.equals(".") || filename.equals("..")) { |
| 422 | continue; |
| 423 | } |
| 424 | SftpFileAttributes fileAttributes = file.attributes(); |
| 425 | JSONObject fileInfo = new JSONObject(); |
| 426 | fileInfo.put("name", filename); |
| 427 | fileInfo.put("exists", true); |
| 428 | |
| 429 | if (fileAttributes != null) { |
| 430 | String permissions = fileAttributes.toPermissionsString(); |
| 431 | boolean canRead = permissions.charAt(1) == 'r'; |
| 432 | boolean canWrite = permissions.charAt(2) == 'w'; |
| 433 | fileInfo.put("canRead", canRead); |
| 434 | fileInfo.put("canWrite", canWrite); |
| 435 | fileInfo.put("permissions", permissions); |
| 436 | fileInfo.put("length", fileAttributes.size()); |
| 437 | fileInfo.put("url", file.getAbsolutePath()); |
| 438 | fileInfo.put( |
| 439 | "lastModified", |
| 440 | fileAttributes.lastModifiedTime() |
| 441 | ); |
| 442 | |
| 443 | if (permissions.charAt(0) == 'l') { |
| 444 | fileInfo.put("isLink", true); |
| 445 | try { |
| 446 | String linkTarget = sftp.getSymbolicLinkTarget( |
| 447 | file.getAbsolutePath() |
| 448 | ); |
| 449 | fileInfo.put("linkTarget", linkTarget); |
| 450 | SftpFileAttributes linkAttributes = sftp.stat( |
| 451 | linkTarget |
| 452 | ); |
| 453 | fileInfo.put("isFile", linkAttributes.isFile()); |
| 454 | fileInfo.put( |
| 455 | "isDirectory", |
| 456 | linkAttributes.isDirectory() |
| 457 | ); |
| 458 | } catch (SftpStatusException | SshException e) { |
| 459 | // Handle broken symlink |
| 460 | fileInfo.put("isFile", false); |
| 461 | fileInfo.put("isDirectory", false); |
| 462 | fileInfo.put("isLink", false); |
| 463 | } |
| 464 | } else { |
| 465 | fileInfo.put("isLink", false); |
| 466 | fileInfo.put("isDirectory", fileAttributes.isDirectory()); |
no test coverage detected