Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Discover
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
6
Merge Requests
6
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Plasma
Discover
Commits
53c31b01
Commit
53c31b01
authored
Jan 14, 2021
by
Aleix Pol Gonzalez
🐧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flatpak: Simplify the size fetching process
parent
2405b765
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
48 deletions
+23
-48
libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
+6
-6
libdiscover/backends/FlatpakBackend/FlatpakFetchDataJob.cpp
libdiscover/backends/FlatpakBackend/FlatpakFetchDataJob.cpp
+16
-35
libdiscover/backends/FlatpakBackend/FlatpakFetchDataJob.h
libdiscover/backends/FlatpakBackend/FlatpakFetchDataJob.h
+1
-7
No files found.
libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
View file @
53c31b01
...
...
@@ -1081,11 +1081,11 @@ bool FlatpakBackend::updateAppSizeFromRemote(FlatpakResource *resource)
return
true
;
}
auto
futureWatcher
=
new
QFutureWatcher
<
FlatpakR
unnables
::
SizeInformation
>
(
this
);
connect
(
futureWatcher
,
&
QFutureWatcher
<
FlatpakR
unnables
::
SizeInformation
>::
finished
,
this
,
[
this
,
resource
,
futureWatcher
]()
{
auto
value
=
futureWatcher
->
result
();
if
(
value
.
valid
)
{
onFetchSizeFinished
(
resource
,
value
.
downloadSize
,
value
.
installedSize
);
auto
futureWatcher
=
new
QFutureWatcher
<
FlatpakR
emoteRef
*
>
(
this
);
connect
(
futureWatcher
,
&
QFutureWatcher
<
FlatpakR
emoteRef
*
>::
finished
,
this
,
[
this
,
resource
,
futureWatcher
]()
{
g_autoptr
(
FlatpakRemoteRef
)
remoteRef
=
futureWatcher
->
result
();
if
(
remoteRef
)
{
onFetchSizeFinished
(
resource
,
flatpak_remote_ref_get_download_size
(
remoteRef
),
flatpak_remote_ref_get_installed_size
(
remoteRef
)
);
}
else
{
resource
->
setPropertyState
(
FlatpakResource
::
DownloadSize
,
FlatpakResource
::
UnknownOrFailed
);
resource
->
setPropertyState
(
FlatpakResource
::
InstalledSize
,
FlatpakResource
::
UnknownOrFailed
);
...
...
@@ -1095,7 +1095,7 @@ bool FlatpakBackend::updateAppSizeFromRemote(FlatpakResource *resource)
resource
->
setPropertyState
(
FlatpakResource
::
DownloadSize
,
FlatpakResource
::
Fetching
);
resource
->
setPropertyState
(
FlatpakResource
::
InstalledSize
,
FlatpakResource
::
Fetching
);
futureWatcher
->
setFuture
(
QtConcurrent
::
run
(
&
m_threadPool
,
&
FlatpakRunnables
::
f
etchFlatpakSize
,
resource
,
m_cancellable
));
futureWatcher
->
setFuture
(
QtConcurrent
::
run
(
&
m_threadPool
,
&
FlatpakRunnables
::
f
indRemoteRef
,
resource
,
m_cancellable
));
}
return
true
;
...
...
libdiscover/backends/FlatpakBackend/FlatpakFetchDataJob.cpp
View file @
53c31b01
...
...
@@ -11,61 +11,42 @@
namespace
FlatpakRunnables
{
static
FlatpakRemoteRef
*
findRemoteRef
(
FlatpakResource
*
app
,
GCancellable
*
cancellable
,
GError
**
error
)
FlatpakRemoteRef
*
findRemoteRef
(
FlatpakResource
*
app
,
GCancellable
*
cancellable
)
{
if
(
app
->
origin
().
isEmpty
())
{
qWarning
()
<<
"Failed to get metadata file because of missing origin"
;
return
nullptr
;
}
g_autoptr
(
GError
)
localError
=
nullptr
;
const
auto
kind
=
app
->
resourceType
()
==
FlatpakResource
::
DesktopApp
?
FLATPAK_REF_KIND_APP
:
FLATPAK_REF_KIND_RUNTIME
;
const
QByteArray
origin
=
app
->
origin
().
toUtf8
(),
name
=
app
->
flatpakName
().
toUtf8
(),
arch
=
app
->
arch
().
toUtf8
(),
branch
=
app
->
branch
().
toUtf8
();
return
flatpak_installation_fetch_remote_ref_sync_full
(
app
->
installation
(),
origin
.
constData
(),
kind
,
name
.
constData
(),
arch
.
constData
(),
branch
.
constData
(),
FLATPAK_QUERY_FLAGS_ONLY_CACHED
,
cancellable
,
error
);
auto
ret
=
flatpak_installation_fetch_remote_ref_sync_full
(
app
->
installation
(),
origin
.
constData
(),
kind
,
name
.
constData
(),
arch
.
constData
(),
branch
.
constData
(),
FLATPAK_QUERY_FLAGS_ONLY_CACHED
,
cancellable
,
&
localError
);
if
(
!
ret
)
{
qWarning
()
<<
"Failed to find:"
<<
app
->
ref
()
<<
"in"
<<
origin
<<
localError
->
message
;
return
{};
}
return
ret
;
}
QByteArray
fetchMetadata
(
FlatpakResource
*
app
,
GCancellable
*
cancellable
)
{
g_autoptr
(
GError
)
localError
=
nullptr
;
FlatpakRemoteRef
*
remote
=
findRemoteRef
(
app
,
cancellable
,
&
localError
);
Q_ASSERT
(
remote
);
Q_ASSERT
(
!
localError
);
QByteArray
metadataContent
;
g_autoptr
(
GBytes
)
data
=
flatpak_remote_ref_get_metadata
(
remote
);
if
(
data
)
{
gsize
len
=
0
;
auto
buff
=
g_bytes_get_data
(
data
,
&
len
);
metadataContent
=
QByteArray
((
const
char
*
)
buff
,
len
);
}
else
{
qWarning
()
<<
"Failed to get metadata file: "
<<
localError
->
message
;
FlatpakRemoteRef
*
remoteRef
=
findRemoteRef
(
app
,
cancellable
);
if
(
!
remoteRef
)
{
qDebug
()
<<
"failed to find the remote"
<<
app
->
name
();
return
{};
}
g_autoptr
(
GBytes
)
data
=
flatpak_remote_ref_get_metadata
(
remoteRef
);
gsize
len
=
0
;
auto
buff
=
g_bytes_get_data
(
data
,
&
len
);
const
QByteArray
metadataContent
((
const
char
*
)
buff
,
len
);
if
(
metadataContent
.
isEmpty
())
{
qWarning
()
<<
"Failed to get metadata file: empty metadata"
;
return
{};
}
return
metadataContent
;
}
SizeInformation
fetchFlatpakSize
(
FlatpakResource
*
app
,
GCancellable
*
cancellable
)
{
g_autoptr
(
GError
)
localError
=
nullptr
;
SizeInformation
ret
;
FlatpakRemoteRef
*
remote
=
findRemoteRef
(
app
,
cancellable
,
&
localError
);
if
(
!
remote
)
{
qWarning
()
<<
"Failed to get remote size of"
<<
app
->
name
()
<<
app
->
origin
()
<<
":"
<<
localError
->
message
;
return
ret
;
}
ret
.
downloadSize
=
flatpak_remote_ref_get_download_size
(
remote
);
ret
.
installedSize
=
flatpak_remote_ref_get_installed_size
(
remote
);
ret
.
valid
=
true
;
return
ret
;
}
}
libdiscover/backends/FlatpakBackend/FlatpakFetchDataJob.h
View file @
53c31b01
...
...
@@ -17,13 +17,7 @@ class FlatpakResource;
namespace
FlatpakRunnables
{
struct
SizeInformation
{
bool
valid
=
false
;
guint64
downloadSize
;
guint64
installedSize
;
};
SizeInformation
fetchFlatpakSize
(
FlatpakResource
*
app
,
GCancellable
*
cancellable
);
FlatpakRemoteRef
*
findRemoteRef
(
FlatpakResource
*
app
,
GCancellable
*
cancellable
);
QByteArray
fetchMetadata
(
FlatpakResource
*
app
,
GCancellable
*
cancellable
);
}
...
...
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