@@ -39,16 +39,19 @@ class RootHelpers {
3939 fun getFiles (context : Context , path : String , callback : (fileDirItems: ArrayList <FileDirItem >) -> Unit ) {
4040 val files = ArrayList <FileDirItem >()
4141 val showHidden = context.config.shouldShowHidden
42+ val SEPARATOR = " |||"
4243
43- val command = object : Command (0 , " ls -la $path | awk '{print \$ 1,\$ NF}'" ) {
44+ val command = object : Command (0 , " ls -la $path | awk '{print \$ 1,\" $SEPARATOR \" ,$4, \" $SEPARATOR \" , \ $ NF}'" ) {
4445 override fun commandOutput (id : Int , line : String ) {
45- val parts = line.split(" " )
46+ val parts = line.split(SEPARATOR )
4647
47- val filename = parts[1 ] .trimStart(' /' )
48+ val filename = parts[2 ].trim() .trimStart(' /' )
4849 if (showHidden || ! filename.startsWith(" ." )) {
4950 val filePath = " ${path.trimEnd(' /' )} /$filename "
50- val isDirectory = parts[0 ].startsWith(" d" )
51- val fileDirItem = FileDirItem (filePath, filename, isDirectory, 0 , 0 )
51+ val permissions = parts[0 ].trim()
52+ val isDirectory = permissions.startsWith(" d" )
53+ val fileSize = if (permissions.startsWith(" -" )) parts[1 ].trim().toLong() else 0L
54+ val fileDirItem = FileDirItem (filePath, filename, isDirectory, 0 , fileSize)
5255 files.add(fileDirItem)
5356 }
5457
@@ -69,17 +72,14 @@ class RootHelpers {
6972
7073 fun getFileDirParameters (oldItems : ArrayList <FileDirItem >, callback : (fileDirItems: ArrayList <FileDirItem >) -> Unit ) {
7174 val files = ArrayList <FileDirItem >()
75+ val shell = RootTools .getShell(true )
7276 oldItems.forEach {
73- val childrenCount = " find ${it.path} -mindepth 1 -maxdepth 1 | wc -l"
74- val fileSize = if (it.isDirectory) " " else " wc -c < ${it.path} "
75- val command = object : Command (0 , " echo $($childrenCount ) $($fileSize )" ) {
77+ val command = object : Command (0 , " find ${it.path} -mindepth 1 -maxdepth 1 | wc -l" ) {
7678 override fun commandOutput (id : Int , line : String ) {
7779 val areDigitsOnly = line.matches(Regex (" [0-9 ]+" ))
7880 if (areDigitsOnly) {
79- val parts = line.split(' ' )
80- val children = parts[0 ].toInt()
81- val bytes = if (parts.size > 1 ) parts[1 ].toLong() else 0L
82- val fileDirItem = FileDirItem (it.path, it.name, it.isDirectory, children, bytes)
81+ val children = line.trim().toInt()
82+ val fileDirItem = FileDirItem (it.path, it.name, it.isDirectory, children, it.size)
8383 files.add(fileDirItem)
8484 }
8585 super .commandOutput(id, line)
@@ -94,7 +94,7 @@ class RootHelpers {
9494 super .commandCompleted(id, exitcode)
9595 }
9696 }
97- RootTools .getShell( true ) .add(command)
97+ shell .add(command)
9898 }
9999 }
100100}
0 commit comments