Skip to content

Commit e9a671c

Browse files
committed
Fix show Windows file separator error.
1 parent 08323da commit e9a671c

File tree

4 files changed

+61
-52
lines changed

4 files changed

+61
-52
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ android {
1212
applicationId "com.tans.tfiletransporter"
1313
minSdkVersion 26
1414
targetSdkVersion 30
15-
versionCode 2
16-
versionName "1.0.1"
15+
versionCode 3
16+
versionName "1.0.2"
1717

1818
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1919
}

app/src/main/java/com/tans/tfiletransporter/ui/activity/filetransport/MyDirFragment.kt

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,30 @@ class MyDirFragment : BaseFragment<MyDirFragmentBinding, MyDirFragmentState>(R.l
8686
.flatMapSingle { oldTree ->
8787
if (!oldTree.notNeedRefresh) {
8888
updateState { oldState ->
89-
val path =
90-
if (oldTree.isRootFileTree()) homePath else Paths.get(homePathString + oldTree.path)
91-
val children = Files.list(path).map { p ->
92-
if (Files.isDirectory(p)) {
93-
DirectoryYoungLeaf(
94-
name = p.fileName.toString(),
95-
childrenCount = Files.list(p).let { s ->
96-
val size = s.count()
97-
s.close()
98-
size
99-
},
100-
lastModified = Files.getLastModifiedTime(p).toMillis()
101-
)
102-
} else {
103-
FileYoungLeaf(
104-
name = p.fileName.toString(),
105-
size = Files.size(p),
106-
lastModified = Files.getLastModifiedTime(p).toMillis()
107-
)
108-
}
109-
}.toList()
89+
val path = if (oldTree.isRootFileTree()) homePath else Paths.get(homePathString + oldTree.path)
90+
val children = if (Files.isReadable(path)) {
91+
Files.list(path).filter { Files.isReadable(it) }.map { p ->
92+
if (Files.isDirectory(p)) {
93+
DirectoryYoungLeaf(
94+
name = p.fileName.toString(),
95+
childrenCount = Files.list(p).let { s ->
96+
val size = s.count()
97+
s.close()
98+
size
99+
},
100+
lastModified = Files.getLastModifiedTime(p).toMillis()
101+
)
102+
} else {
103+
FileYoungLeaf(
104+
name = p.fileName.toString(),
105+
size = Files.size(p),
106+
lastModified = Files.getLastModifiedTime(p).toMillis()
107+
)
108+
}
109+
}.toList()
110+
} else {
111+
emptyList()
112+
}
110113
oldState.copy(
111114
fileTree = children.refreshFileTree(oldTree),
112115
selectedFiles = emptySet()

app/src/main/java/com/tans/tfiletransporter/ui/activity/filetransport/RemoteDirFragment.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ class RemoteDirFragment : BaseFragment<RemoteDirFragmentBinding, RemoteDirState>
9090
}
9191
oldState.copy(
9292
fileTree = Optional.of(
93-
children.refreshFileTree(
94-
oldTree
95-
)
93+
children.refreshFileTree(
94+
parentTree = oldTree,
95+
dirSeparator = fileTransportScopeData.remoteDirSeparator
96+
)
9697
), selectedFiles = emptySet()
9798
)
9899
}.map {

app/src/main/java/com/tans/tfiletransporter/ui/activity/filetransport/activity/FileTransportActivityWriter.kt

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,37 @@ suspend fun newFolderChildrenShareWriterHandle(
4545
): FolderChildrenShareWriterHandle {
4646
val jsonData = withContext(Dispatchers.IO) {
4747
val path = Paths.get(FileConstants.homePathString + parentPath)
48-
val children = Files.list(path)
49-
.map { p ->
50-
val name = p.fileName.toString()
51-
val lastModify = OffsetDateTime.ofInstant(Instant.ofEpochMilli(Files.getLastModifiedTime(p).toMillis()), ZoneId.systemDefault())
52-
val pathString = if (parentPath.endsWith(FileConstants.FILE_SEPARATOR)) parentPath + name else parentPath + FileConstants.FILE_SEPARATOR + name
53-
if (Files.isDirectory(p)) {
54-
Folder(
55-
name = name,
56-
path = pathString,
57-
childCount = p.let {
58-
val s = Files.list(it)
59-
val size = s.count()
60-
s.close()
61-
size
62-
},
63-
lastModify = lastModify
64-
)
65-
} else {
66-
File(
67-
name = name,
68-
path = pathString,
69-
size = Files.size(p),
70-
lastModify = lastModify
71-
)
72-
}
73-
}.toList()
48+
val children = if (Files.isReadable(path)) {
49+
Files.list(path)
50+
.filter { Files.isReadable(it) }
51+
.map<Any> { p ->
52+
val name = p.fileName.toString()
53+
val lastModify = OffsetDateTime.ofInstant(Instant.ofEpochMilli(Files.getLastModifiedTime(p).toMillis()), ZoneId.systemDefault())
54+
val pathString = if (parentPath.endsWith(FileConstants.FILE_SEPARATOR)) parentPath + name else parentPath + FileConstants.FILE_SEPARATOR + name
55+
if (Files.isDirectory(p)) {
56+
Folder(
57+
name = name,
58+
path = pathString,
59+
childCount = p.let {
60+
val s = Files.list(it)
61+
val size = s.count()
62+
s.close()
63+
size
64+
},
65+
lastModify = lastModify
66+
)
67+
} else {
68+
File(
69+
name = name,
70+
path = pathString,
71+
size = Files.size(p),
72+
lastModify = lastModify
73+
)
74+
}
75+
}.toList()
76+
} else {
77+
emptyList()
78+
}
7479
val responseFolder = ResponseFolderModel(
7580
path = parentPath,
7681
childrenFiles = children.filterIsInstance<File>(),

0 commit comments

Comments
 (0)