diff --git a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp index 31eee911cb138102da4573430895eb83e6c39769..ad20b7f37ad7cd4bfeae0795a3ca2ac0a22ec729 100644 --- a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp @@ -52,17 +52,17 @@ static tuple JudgeExistAndEmpty(const string &path) static int RmDirectory(const string &path) { filesystem::path pathName(path); - std::error_code errCode; - if (filesystem::exists(pathName, errCode)) { - std::error_code errCode; - (void)filesystem::remove_all(pathName, errCode); - if (errCode.value() != 0) { - HILOGE("Failed to remove directory, error code: %{public}d", errCode.value()); - return errCode.value(); + std::error_code existsErrCode; + if (filesystem::exists(pathName, existsErrCode)) { + std::error_code removeErrCode; + (void)filesystem::remove_all(pathName, removeErrCode); + if (removeErrCode.value() != 0) { + HILOGE("Failed to remove directory, error code: %{public}d", removeErrCode.value()); + return removeErrCode.value(); } - } else if (errCode.value() != ERRNO_NOERR) { - HILOGE("fs exists fail, errcode is %{public}d", errCode.value()); - return errCode.value(); + } else if (existsErrCode.value() != ERRNO_NOERR) { + HILOGE("fs exists fail, errcode is %{public}d", existsErrCode.value()); + return existsErrCode.value(); } return ERRNO_NOERR; } diff --git a/interfaces/kits/js/src/mod_fs/properties/movedir_core.cpp b/interfaces/kits/js/src/mod_fs/properties/movedir_core.cpp index 2b7e49e8dc4eb762ac48d24d7cac535b6d6650fd..df5797e656ebb3dec0f83adcd66d6362dbdd6ae0 100644 --- a/interfaces/kits/js/src/mod_fs/properties/movedir_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/movedir_core.cpp @@ -50,17 +50,17 @@ static tuple JudgeExistAndEmpty(const string &path) static int RmDirectory(const string &path) { filesystem::path pathName(path); - std::error_code errCode; - if (filesystem::exists(pathName, errCode)) { - std::error_code errCode; - (void)filesystem::remove_all(pathName, errCode); - if (errCode.value() != 0) { - HILOGE("Failed to remove directory, error code: %{public}d", errCode.value()); - return errCode.value(); + std::error_code existsErrCode; + if (filesystem::exists(pathName, existsErrCode)) { + std::error_code removeErrCode; + (void)filesystem::remove_all(pathName, removeErrCode); + if (removeErrCode.value() != 0) { + HILOGE("Failed to remove directory, error code: %{public}d", removeErrCode.value()); + return removeErrCode.value(); } - } else if (errCode.value() != ERRNO_NOERR) { - HILOGE("Fs exists fail, errcode is %{public}d", errCode.value()); - return errCode.value(); + } else if (existsErrCode.value() != ERRNO_NOERR) { + HILOGE("Fs exists fail, errcode is %{public}d", existsErrCode.value()); + return existsErrCode.value(); } return ERRNO_NOERR; }