Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Jan Paul Batrina
Ark
Commits
0aec0e08
Commit
0aec0e08
authored
Aug 17, 2020
by
Alexey Ivanov
🐢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
libzipplugin.cpp: replace zip_fopen/zip_fclose with unique_ptr
parent
aa4a790d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
13 deletions
+7
-13
plugins/libzipplugin/libzipplugin.cpp
plugins/libzipplugin/libzipplugin.cpp
+7
-13
No files found.
plugins/libzipplugin/libzipplugin.cpp
View file @
0aec0e08
...
...
@@ -479,9 +479,9 @@ bool LibzipPlugin::testArchive()
return
false
;
}
zip_file
*
zipFile
=
zip_fopen_index
(
archive
,
i
,
0
);
std
::
unique_ptr
<
zip_file
,
decltype
(
&
zip_fclose
)
>
zipFile
{
zip_fopen_index
(
archive
,
i
,
0
)
,
&
zip_fclose
}
;
std
::
unique_ptr
<
uchar
[]
>
buf
(
new
uchar
[
statBuffer
.
size
]);
const
int
len
=
zip_fread
(
zipFile
,
buf
.
get
(),
statBuffer
.
size
)
;
const
int
len
=
zip_fread
(
zipFile
.
get
()
,
buf
.
get
(),
statBuffer
.
size
)
if
(
len
==
-
1
||
uint
(
len
)
!=
statBuffer
.
size
)
{
qCCritical
(
ARK
)
<<
"Failed to read data for"
<<
statBuffer
.
name
;
return
false
;
...
...
@@ -491,9 +491,6 @@ bool LibzipPlugin::testArchive()
return
false
;
}
// Free libzip file entry from the memory
zip_fclose
(
zipFile
);
emit
progress
(
float
(
i
)
/
nofEntries
);
}
...
...
@@ -676,11 +673,10 @@ bool LibzipPlugin::extractEntry(zip_t *archive, const QString &entry, const QStr
}
// Handle password-protected files.
zip_file
*
zipFile
=
nullptr
;
std
::
unique_ptr
<
zip_file
,
decltype
(
&
zip_fclose
)
>
zipFile
{
zip_fopen
(
archive
,
entry
.
toUtf8
().
constData
(),
0
),
&
zip_fclose
}
;
bool
firstTry
=
true
;
while
(
!
zipFile
)
{
zipFile
=
zip_fopen
(
archive
,
entry
.
toUtf8
().
constData
(),
0
);
if
(
zipFile
)
{
while
(
!
zipFile
.
get
())
{
if
(
zipFile
.
get
())
{
break
;
}
else
if
(
zip_error_code_zip
(
zip_get_error
(
archive
))
==
ZIP_ER_NOPASSWD
||
zip_error_code_zip
(
zip_get_error
(
archive
))
==
ZIP_ER_WRONGPASSWD
)
{
...
...
@@ -718,7 +714,7 @@ bool LibzipPlugin::extractEntry(zip_t *archive, const QString &entry, const QStr
qulonglong
sum
=
0
;
char
buf
[
1000
];
while
(
sum
!=
statBuffer
.
size
)
{
const
auto
readBytes
=
zip_fread
(
zipFile
,
buf
,
1000
);
const
auto
readBytes
=
zip_fread
(
zipFile
.
get
()
,
buf
,
1000
);
if
(
readBytes
<
0
)
{
qCCritical
(
ARK
)
<<
"Failed to read data"
;
emit
error
(
xi18n
(
"Failed to read data for entry: %1"
,
entry
));
...
...
@@ -758,8 +754,6 @@ bool LibzipPlugin::extractEntry(zip_t *archive, const QString &entry, const QStr
break
;
}
// Free libzip file entry from the memory
zip_fclose
(
zipFile
);
// Close extracted file, flush any buffered data
file
.
close
();
}
...
...
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