Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
Discover
Commits
3722c1ef
Commit
3722c1ef
authored
Apr 30, 2021
by
Aleix Pol Gonzalez
🐧
Browse files
flatpak: no need to copy local files over
parent
b1aeb800
Changes
1
Hide whitespace changes
Inline
Side-by-side
libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp
View file @
3722c1ef
...
...
@@ -140,25 +140,29 @@ public:
void
start
()
{
if
(
m_url
.
isLocalFile
())
{
processFile
(
m_url
);
return
;
}
QNetworkRequest
req
(
m_url
);
req
.
setAttribute
(
QNetworkRequest
::
FollowRedirectsAttribute
,
true
);
auto
replyGet
=
get
(
req
);
connect
(
replyGet
,
&
QNetworkReply
::
finished
,
this
,
[
this
,
replyGet
]
{
QScopedPointer
<
QNetworkReply
,
QScopedPointerDeleteLater
>
replyPtr
(
replyGet
);
const
QUrl
originalUrl
=
replyGet
->
request
().
url
();
if
(
replyGet
->
error
()
!=
QNetworkReply
::
NoError
)
{
qWarning
()
<<
"couldn't download"
<<
originalU
rl
<<
replyGet
->
errorString
();
qWarning
()
<<
"couldn't download"
<<
m_u
rl
<<
replyGet
->
errorString
();
Q_EMIT
jobFinished
(
false
,
nullptr
);
return
;
}
const
QUrl
fileUrl
=
QUrl
::
fromLocalFile
(
QStandardPaths
::
writableLocation
(
QStandardPaths
::
TempLocation
)
//
+
QLatin1Char
(
'/'
)
+
originalU
rl
.
fileName
());
+
QLatin1Char
(
'/'
)
+
m_u
rl
.
fileName
());
auto
replyPut
=
put
(
QNetworkRequest
(
fileUrl
),
replyGet
->
readAll
());
connect
(
replyPut
,
&
QNetworkReply
::
finished
,
this
,
[
this
,
originalUrl
,
fileUrl
,
replyPut
]()
{
connect
(
replyPut
,
&
QNetworkReply
::
finished
,
this
,
[
this
,
fileUrl
,
replyPut
]()
{
QScopedPointer
<
QNetworkReply
,
QScopedPointerDeleteLater
>
replyPtr
(
replyPut
);
if
(
replyPut
->
error
()
!=
QNetworkReply
::
NoError
)
{
qWarning
()
<<
"couldn't save"
<<
originalU
rl
<<
replyPut
->
errorString
();
qWarning
()
<<
"couldn't save"
<<
m_u
rl
<<
replyPut
->
errorString
();
Q_EMIT
jobFinished
(
false
,
nullptr
);
return
;
}
...
...
@@ -167,26 +171,34 @@ public:
return
;
}
FlatpakResource
*
resource
=
nullptr
;
if
(
fileUrl
.
path
().
endsWith
(
QLatin1String
(
".flatpak"
)))
{
resource
=
m_backend
->
addAppFromFlatpakBundle
(
fileUrl
);
}
else
if
(
fileUrl
.
path
().
endsWith
(
QLatin1String
(
".flatpakref"
)))
{
resource
=
m_backend
->
addAppFromFlatpakRef
(
fileUrl
);
}
else
if
(
fileUrl
.
path
().
endsWith
(
QLatin1String
(
".flatpakrepo"
)))
{
resource
=
m_backend
->
addSourceFromFlatpakRepo
(
fileUrl
);
}
if
(
resource
)
{
resource
->
setResourceFile
(
originalUrl
);
Q_EMIT
jobFinished
(
true
,
resource
);
}
else
{
qWarning
()
<<
"couldn't create resource from"
<<
fileUrl
.
toLocalFile
();
Q_EMIT
jobFinished
(
false
,
nullptr
);
}
processFile
(
fileUrl
);
});
});
}
void
processFile
(
const
QUrl
&
fileUrl
)
{
FlatpakResource
*
resource
=
nullptr
;
const
auto
path
=
fileUrl
.
toLocalFile
();
if
(
path
.
endsWith
(
QLatin1String
(
".flatpak"
)))
{
resource
=
m_backend
->
addAppFromFlatpakBundle
(
fileUrl
);
}
else
if
(
path
.
endsWith
(
QLatin1String
(
".flatpakref"
)))
{
resource
=
m_backend
->
addAppFromFlatpakRef
(
fileUrl
);
}
else
if
(
path
.
endsWith
(
QLatin1String
(
".flatpakrepo"
)))
{
resource
=
m_backend
->
addSourceFromFlatpakRepo
(
fileUrl
);
}
else
{
qWarning
()
<<
"unrecognized format"
<<
fileUrl
;
}
if
(
resource
)
{
resource
->
setResourceFile
(
m_url
);
Q_EMIT
jobFinished
(
true
,
resource
);
}
else
{
qWarning
()
<<
"couldn't create resource from"
<<
fileUrl
<<
m_url
;
Q_EMIT
jobFinished
(
false
,
nullptr
);
}
}
Q_SIGNALS:
void
jobFinished
(
bool
success
,
FlatpakResource
*
resource
);
...
...
Write
Preview
Supports
Markdown
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