mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-30 13:35:27 +00:00
Truncate file only if needed
This commit is contained in:
parent
9fe8741a02
commit
f95478f1f1
@ -248,9 +248,12 @@ bool sepolicy::to_file(const char *file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int fd = xopen(file, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
|
||||
int fd = xopen(file, O_WRONLY | O_CREAT | O_CLOEXEC, 0644);
|
||||
if (fd < 0)
|
||||
return false;
|
||||
if (struct stat st{}; xfstat(fd, &st) == 0 && st.st_size > 0) {
|
||||
ftruncate(fd, 0);
|
||||
}
|
||||
xwrite(fd, data.buf, data.sz);
|
||||
|
||||
close(fd);
|
||||
|
Loading…
Reference in New Issue
Block a user