Skip to content

Commit

Permalink
Merge pull request #3960 from TeamAmaze/bugfix/parseFileLinesForLegac…
Browse files Browse the repository at this point in the history
…yDevices

Fix ls lines for (even more) legacy devices
  • Loading branch information
VishalNehra authored Oct 30, 2023
2 parents 0a20267 + 921b3c6 commit 0beaea2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicLong;

import org.slf4j.Logger;
Expand Down Expand Up @@ -865,10 +867,19 @@ public static HybridFileParcelable parseName(String line, boolean isStat) {
}
link = new StringBuilder(link.toString().trim());
}
long Size = (size == null || size.trim().length() == 0) ? -1 : Long.parseLong(size);
long Size;
if (size == null || size.trim().length() == 0) {
Size = -1;
} else {
try {
Size = Long.parseLong(size);
} catch (NumberFormatException ifItIsNotANumber) {
Size = -1;
}
}
if (date.trim().length() > 0 && !isStat) {
ParsePosition pos = new ParsePosition(0);
SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd | HH:mm");
SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd | HH:mm", Locale.US);
Date stringDate = simpledateformat.parse(date, pos);
if (stringDate == null) {
LOG.warn("parseName: unable to parse datetime string [" + date + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.amaze.filemanager.filesystem.files.FileUtils.getPathsInPath
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.Config
Expand Down Expand Up @@ -364,6 +366,26 @@ class FileUtilsTest {
}
}

/**
* Test [FileUtils.parseName] for special cases
*/
@Test
fun testParseStringForSpecialCases() {
// Found on TranceLove's GPD XD Gen 1 running LegacyROM (4.4.4) that dirs doesn't even
// report default folder node size = 4096 or anything
val lsLine = "drwxr-xr-x root root 2023-10-21 13:57 acct"

val systemTz = TimeZone.getDefault()
TimeZone.setDefault(TimeZone.getTimeZone("UTC"))

val result = FileUtils.parseName(lsLine, false)
assertNotNull(result)
assertEquals("acct", result.name)
assertEquals("drwxr-xr-x", result.permission)
assertTrue(result.isDirectory)
TimeZone.setDefault(systemTz)
}

/**
* Test [FileUtils.parseName]
*/
Expand Down

0 comments on commit 0beaea2

Please sign in to comment.