mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-22 07:57:39 +00:00
Support moving files across filesystems
This commit is contained in:
parent
d1be34c34a
commit
599ae95251
@ -51,7 +51,7 @@ struct node_entry {
|
|||||||
static void concat_path(struct node_entry *node) {
|
static void concat_path(struct node_entry *node) {
|
||||||
if (node->parent)
|
if (node->parent)
|
||||||
concat_path(node->parent);
|
concat_path(node->parent);
|
||||||
int len = strlen(buf);
|
size_t len = strlen(buf);
|
||||||
buf[len] = '/';
|
buf[len] = '/';
|
||||||
strcpy(buf + len + 1, node->name);
|
strcpy(buf + len + 1, node->name);
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,11 @@
|
|||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
#include <sys/sendfile.h>
|
||||||
#include <linux/loop.h>
|
#include <linux/loop.h>
|
||||||
|
|
||||||
#include "magisk.h"
|
#include "magisk.h"
|
||||||
@ -167,7 +169,15 @@ int merge_img(const char *source, const char *target) {
|
|||||||
return 0;
|
return 0;
|
||||||
LOGI("* Merging %s -> %s\n", source, target);
|
LOGI("* Merging %s -> %s\n", source, target);
|
||||||
if (access(target, F_OK) == -1) {
|
if (access(target, F_OK) == -1) {
|
||||||
xrename(source, target);
|
if (rename(source, target) < 0) {
|
||||||
|
// Copy and remove
|
||||||
|
int tgt = creat(target, 0644);
|
||||||
|
int src = xopen(source, O_RDONLY | O_CLOEXEC);
|
||||||
|
sendfile(tgt, src, 0, INT_MAX);
|
||||||
|
close(tgt);
|
||||||
|
close(src);
|
||||||
|
unlink(source);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user