Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
f1fb7404
Commit
f1fb7404
authored
Jul 21, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Catch exceptions when loading remote modules
Fix #3004
parent
fc67c019
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
16 deletions
+23
-16
RepoUpdater.kt
.../main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt
+23
-16
No files found.
app/src/main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt
View file @
f1fb7404
...
@@ -5,6 +5,7 @@ import com.topjohnwu.magisk.core.Const
...
@@ -5,6 +5,7 @@ import com.topjohnwu.magisk.core.Const
import
com.topjohnwu.magisk.core.model.module.Repo
import
com.topjohnwu.magisk.core.model.module.Repo
import
com.topjohnwu.magisk.data.database.RepoDao
import
com.topjohnwu.magisk.data.database.RepoDao
import
com.topjohnwu.magisk.data.network.GithubApiServices
import
com.topjohnwu.magisk.data.network.GithubApiServices
import
com.topjohnwu.magisk.ktx.synchronized
import
kotlinx.coroutines.*
import
kotlinx.coroutines.*
import
timber.log.Timber
import
timber.log.Timber
import
java.net.HttpURLConnection
import
java.net.HttpURLConnection
...
@@ -64,33 +65,39 @@ class RepoUpdater(
...
@@ -64,33 +65,39 @@ class RepoUpdater(
page
:
Int
=
1
,
page
:
Int
=
1
,
etag
:
String
=
""
etag
:
String
=
""
):
PageResult
=
coroutineScope
{
):
PageResult
=
coroutineScope
{
val
result
=
api
.
fetchRepos
(
page
,
etag
)
runCatching
{
result
.
run
{
val
result
=
api
.
fetchRepos
(
page
,
etag
)
if
(
code
()
==
HttpURLConnection
.
HTTP_NOT_MODIFIED
)
result
.
run
{
return
@coroutineScope
PageResult
.
CACHED
if
(
code
()
==
HttpURLConnection
.
HTTP_NOT_MODIFIED
)
return
@coroutineScope
PageResult
.
CACHED
if
(!
isSuccessful
)
if
(!
isSuccessful
)
return
@coroutineScope
PageResult
.
ERROR
return
@coroutineScope
PageResult
.
ERROR
if
(
page
==
1
)
if
(
page
==
1
)
repoDB
.
etagKey
=
headers
()[
Const
.
Key
.
ETAG_KEY
].
orEmpty
().
trimEtag
()
repoDB
.
etagKey
=
headers
()[
Const
.
Key
.
ETAG_KEY
].
orEmpty
().
trimEtag
()
val
repoLoad
=
async
{
loadRepos
(
body
()
!!
,
cached
)
}
val
repoLoad
=
async
{
loadRepos
(
body
()
!!
,
cached
)
}
val
next
=
if
(
headers
()[
Const
.
Key
.
LINK_KEY
].
orEmpty
().
contains
(
"next"
))
{
val
next
=
if
(
headers
()[
Const
.
Key
.
LINK_KEY
].
orEmpty
().
contains
(
"next"
))
{
async
{
loadPage
(
cached
,
page
+
1
)
}
async
{
loadPage
(
cached
,
page
+
1
)
}
}
else
{
}
else
{
async
{
PageResult
.
SUCCESS
}
async
{
PageResult
.
SUCCESS
}
}
repoLoad
.
await
()
return
@coroutineScope
next
.
await
()
}
}
repoLoad
.
await
()
}.
getOrElse
{
return
@coroutineScope
next
.
await
()
Timber
.
e
(
it
)
PageResult
.
ERROR
}
}
}
}
suspend
operator
fun
invoke
(
forced
:
Boolean
)
=
withContext
(
Dispatchers
.
IO
)
{
suspend
operator
fun
invoke
(
forced
:
Boolean
)
=
withContext
(
Dispatchers
.
IO
)
{
val
cached
=
Collections
.
synchronizedSet
(
HashSet
(
repoDB
.
repoIDList
)
)
val
cached
=
HashSet
(
repoDB
.
repoIDList
).
synchronized
(
)
when
(
loadPage
(
cached
,
etag
=
repoDB
.
etagKey
))
{
when
(
loadPage
(
cached
,
etag
=
repoDB
.
etagKey
))
{
PageResult
.
CACHED
->
if
(
forced
)
forcedReload
(
cached
)
PageResult
.
CACHED
->
if
(
forced
)
forcedReload
(
cached
)
PageResult
.
SUCCESS
->
repoDB
.
removeRepos
(
cached
)
PageResult
.
SUCCESS
->
repoDB
.
removeRepos
(
cached
)
PageResult
.
ERROR
->
Unit
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment