Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ls lines for (even more) legacy devices #3960

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

Check notice on line 34 in app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java#L34

Unused import - java.util.concurrent.Callable.
import java.util.concurrent.atomic.AtomicLong;

import org.slf4j.Logger;
Expand Down Expand Up @@ -865,10 +867,19 @@
}
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
Loading