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
1b4a6850
Commit
1b4a6850
authored
Aug 07, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure parent folders exist before extract
parent
07b45f39
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
10 deletions
+17
-10
files.cpp
native/src/base/files.cpp
+6
-4
files.hpp
native/src/base/files.hpp
+1
-1
cpio.cpp
native/src/boot/cpio.cpp
+10
-5
No files found.
native/src/base/files.cpp
View file @
1b4a6850
...
...
@@ -23,19 +23,21 @@ int fd_pathat(int dirfd, const char *name, char *path, size_t size) {
return
0
;
}
int
mkdirs
(
string
path
,
mode_t
mode
)
{
int
mkdirs
(
const
char
*
path
,
mode_t
mode
)
{
char
buf
[
4096
];
strlcpy
(
buf
,
path
,
sizeof
(
buf
));
errno
=
0
;
for
(
char
*
p
=
path
.
data
()
+
1
;
*
p
;
++
p
)
{
for
(
char
*
p
=
&
buf
[
1
]
;
*
p
;
++
p
)
{
if
(
*
p
==
'/'
)
{
*
p
=
'\0'
;
if
(
mkdir
(
path
.
data
()
,
mode
)
==
-
1
)
{
if
(
mkdir
(
buf
,
mode
)
==
-
1
)
{
if
(
errno
!=
EEXIST
)
return
-
1
;
}
*
p
=
'/'
;
}
}
if
(
mkdir
(
path
.
data
()
,
mode
)
==
-
1
)
{
if
(
mkdir
(
buf
,
mode
)
==
-
1
)
{
if
(
errno
!=
EEXIST
)
return
-
1
;
}
...
...
native/src/base/files.hpp
View file @
1b4a6850
...
...
@@ -60,7 +60,7 @@ struct mmap_data : public byte_data {
ssize_t
fd_path
(
int
fd
,
char
*
path
,
size_t
size
);
int
fd_pathat
(
int
dirfd
,
const
char
*
name
,
char
*
path
,
size_t
size
);
int
mkdirs
(
std
::
string
path
,
mode_t
mode
);
int
mkdirs
(
const
char
*
path
,
mode_t
mode
);
void
rm_rf
(
const
char
*
path
);
void
mv_path
(
const
char
*
src
,
const
char
*
dest
);
void
mv_dir
(
int
src
,
int
dest
);
...
...
native/src/boot/cpio.cpp
View file @
1b4a6850
#include <unistd.h>
#include <fcntl.h>
#include <libgen.h>
#include <algorithm>
#include <base.hpp>
...
...
@@ -79,17 +80,21 @@ void cpio::extract_entry(const entry_map::value_type &e, const char *file) {
fprintf
(
stderr
,
"Extract [%s] to [%s]
\n
"
,
e
.
first
.
data
(),
file
);
unlink
(
file
);
rmdir
(
file
);
// Make sure parent folders exist
char
*
parent
=
dirname
(
file
);
xmkdirs
(
parent
,
0755
);
if
(
S_ISDIR
(
e
.
second
->
mode
))
{
::
mkdir
(
file
,
e
.
second
->
mode
&
0777
);
x
mkdir
(
file
,
e
.
second
->
mode
&
0777
);
}
else
if
(
S_ISREG
(
e
.
second
->
mode
))
{
int
fd
=
creat
(
file
,
e
.
second
->
mode
&
0777
);
int
fd
=
xopen
(
file
,
O_CREAT
|
O_WRONLY
|
O_TRUNC
,
e
.
second
->
mode
&
0777
);
xwrite
(
fd
,
e
.
second
->
data
,
e
.
second
->
filesize
);
fchown
(
fd
,
e
.
second
->
uid
,
e
.
second
->
gid
);
close
(
fd
);
}
else
if
(
S_ISLNK
(
e
.
second
->
mode
))
{
auto
target
=
strndup
((
char
*
)
e
.
second
->
data
,
e
.
second
->
filesize
);
}
else
if
(
S_ISLNK
(
e
.
second
->
mode
)
&&
e
.
second
->
filesize
<
4096
)
{
char
target
[
4096
];
memcpy
(
target
,
e
.
second
->
data
,
e
.
second
->
filesize
);
target
[
e
.
second
->
filesize
]
=
'\0'
;
symlink
(
target
,
file
);
free
(
target
);
}
}
...
...
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