From f0263be6ee730c7866027dfe4febfae53214c716 Mon Sep 17 00:00:00 2001 From: chensihan Date: Mon, 6 Jan 2025 11:49:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=98=B2=E6=AD=A2=E6=AD=BB=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=20Signed-off-by:=20chensihan=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/native/backup_ext/src/untar_file.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frameworks/native/backup_ext/src/untar_file.cpp b/frameworks/native/backup_ext/src/untar_file.cpp index cbba3debb..a78d2227d 100644 --- a/frameworks/native/backup_ext/src/untar_file.cpp +++ b/frameworks/native/backup_ext/src/untar_file.cpp @@ -461,6 +461,9 @@ ErrFileInfo UntarFile::ParseRegularFile(FileStatInfo &info) readBuffSize = remainSize; } auto readSize = fread(&destStr[0], sizeof(char), readBuffSize, tarFilePtr_); + if (readSize == 0) { + break; + } if (readSize != readBuffSize) { readBuffSize = readSize; } -- Gitee From 0e13333c113948890b0c9f160163bf8291254bd0 Mon Sep 17 00:00:00 2001 From: chensihan Date: Mon, 6 Jan 2025 14:55:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A4=84=E7=90=86=E8=B6=85=E5=A4=A7?= =?UTF-8?q?=E5=87=BD=E6=95=B0=20Signed-off-by:=20chensihan=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../native/backup_ext/include/untar_file.h | 8 ++++ .../native/backup_ext/src/untar_file.cpp | 41 +++++++++++-------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/frameworks/native/backup_ext/include/untar_file.h b/frameworks/native/backup_ext/include/untar_file.h index e08be8853..adf1a07ee 100644 --- a/frameworks/native/backup_ext/include/untar_file.h +++ b/frameworks/native/backup_ext/include/untar_file.h @@ -102,6 +102,14 @@ private: */ FILE *CreateFile(std::string &path); + /** + * @brief mod and stat regular file + * + * @param info 文件属性结构体 + * @param errFileInfo 失败文件信息 + */ + void ModAndStatFile(FileStatInfo &info, ErrFileInfo &errFileInfo); + /** * @brief parse regular file * diff --git a/frameworks/native/backup_ext/src/untar_file.cpp b/frameworks/native/backup_ext/src/untar_file.cpp index a78d2227d..22fcbd0b4 100644 --- a/frameworks/native/backup_ext/src/untar_file.cpp +++ b/frameworks/native/backup_ext/src/untar_file.cpp @@ -447,6 +447,28 @@ std::tuple UntarFile::ParseIncrementalFileByTypeFlag(cha return {0, isFilter, errFileInfo}; } +void UntarFile::ModAndStatFile(FileStatInfo &info, ErrFileInfo &errFileInfo) +{ + if (chmod(info.fullPath.data(), info.mode) != 0) { + HILOGE("Failed to chmod of %{public}s, err = %{public}d", GetAnonyPath(info.fullPath).c_str(), errno); + errFileInfo[info.fullPath].push_back(errno); + } + struct utimbuf times; + struct stat attr; + if (stat(info.fullPath.c_str(), &attr) != 0) { + errFileInfo[info.fullPath].push_back(errno); + HILOGE("Failed to get stat of %{public}s, err = %{public}d", GetAnonyPath(info.fullPath).c_str(), errno); + times.actime = info.mtime; + } else { + times.actime = attr.st_atime; + } + times.modtime = info.mtime; + if (info.mtime != 0 && utime(info.fullPath.c_str(), ×) != 0) { + errFileInfo[info.fullPath].push_back(errno); + HILOGE("Failed to set mtime of %{public}s, err = %{public}d", GetAnonyPath(info.fullPath).c_str(), errno); + } +} + ErrFileInfo UntarFile::ParseRegularFile(FileStatInfo &info) { ErrFileInfo errFileInfo; @@ -474,24 +496,7 @@ ErrFileInfo UntarFile::ParseRegularFile(FileStatInfo &info) remainSize -= readBuffSize; } fclose(destFile); - if (chmod(info.fullPath.data(), info.mode) != 0) { - HILOGE("Failed to chmod of %{public}s, err = %{public}d", GetAnonyPath(info.fullPath).c_str(), errno); - errFileInfo[info.fullPath].push_back(errno); - } - struct utimbuf times; - struct stat attr; - if (stat(info.fullPath.c_str(), &attr) != 0) { - errFileInfo[info.fullPath].push_back(errno); - HILOGE("Failed to get stat of %{public}s, err = %{public}d", GetAnonyPath(info.fullPath).c_str(), errno); - times.actime = info.mtime; - } else { - times.actime = attr.st_atime; - } - times.modtime = info.mtime; - if (info.mtime != 0 && utime(info.fullPath.c_str(), ×) != 0) { - errFileInfo[info.fullPath].push_back(errno); - HILOGE("Failed to set mtime of %{public}s, err = %{public}d", GetAnonyPath(info.fullPath).c_str(), errno); - } + ModAndStatFile(info, errFileInfo); // anyway, go to correct fseeko(tarFilePtr_, pos_ + tarFileBlockCnt_ * BLOCK_SIZE, SEEK_SET); } else { -- Gitee