static bool copy_file(const char *newsrc, const char *newdst, int mode)
{
- const int src_file = open(newsrc, O_RDONLY);
- if (src_file == -1) {
- SLOGE("Cannot open file %s: (%d) %m", newsrc, errno);
- return false;
- }
-
- const int dst_file = open(newdst, O_CREAT | O_WRONLY, mode);
- if (dst_file == -1) {
- close(src_file);
- SLOGE("Cannot open file %s: (%d) %m", newdst, errno);
- return false;
- }
-
- bool ret = true;
- struct stat fileinfo = {0};
- if (fstat(src_file, &fileinfo) == -1) {
- SLOGE("Get file %s status error: (%d) %m", newsrc, errno);
- ret = false;
- goto exit;
- }
-
- if (sendfile(dst_file, src_file, NULL, fileinfo.st_size) == -1) {
- SLOGE("Copy file content (%s -> %s) error: (%d) %m", newsrc, newdst, errno);
- ret = false;
- goto exit;
- }
+ const int src_file = open(newsrc, O_RDONLY);
+ if (src_file == -1) {
+ SLOGE("Cannot open file %s: (%d) %m", newsrc, errno);
+ return false;
+ }
+
+ const int dst_file = open(newdst, O_CREAT | O_WRONLY, mode);
+ if (dst_file == -1) {
+ close(src_file);
+ SLOGE("Cannot open file %s: (%d) %m", newdst, errno);
+ return false;
+ }
+
+ bool ret = true;
+ struct stat fileinfo = {0};
+ if (fstat(src_file, &fileinfo) == -1) {
+ SLOGE("Get file %s status error: (%d) %m", newsrc, errno);
+ ret = false;
+ goto exit;
+ }
+
+ if (sendfile(dst_file, src_file, NULL, fileinfo.st_size) == -1) {
+ SLOGE("Copy file content (%s -> %s) error: (%d) %m", newsrc, newdst, errno);
+ ret = false;
+ goto exit;
+ }
exit:
- close(src_file);
- close(dst_file);
- return ret;
+ close(src_file);
+ close(dst_file);
+ return ret;
}
static int copy_content(const char *src, const char *dst, const char **exclude)