Skip to content

Commit 4cf9355

Browse files
committed
fix:1.12.15, 解决GetFileType()识别不了符号链接文件的问题
1 parent c8dfcbb commit 4cf9355

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

modules/util/fs.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ using std::ifstream;
4040
using std::ofstream;
4141
using std::exception;
4242

43-
FileType GetFileType(const std::string &file_path)
43+
FileType GetFileType(const std::string &file_path, bool refer_to_real_file)
4444
{
45-
struct stat st;
45+
auto func = refer_to_real_file ? (::stat) : (::lstat);
4646

47-
if (::stat(file_path.c_str(), &st) == 0) {
47+
struct stat st;
48+
if (func(file_path.c_str(), &st) == 0) {
4849
if (S_ISDIR(st.st_mode)) return FileType::kDirectory;
4950
if (S_ISREG(st.st_mode)) return FileType::kRegular;
5051
if (S_ISCHR(st.st_mode)) return FileType::kCharacterDevice;

modules/util/fs.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ enum class FileType {
4747
/**
4848
* 获取文件类型
4949
*
50-
* \param file_path 文件路径
50+
* \param file_path 文件路径
51+
* \param refer_to_real_file 如果是符号链接文件,是否指向真实的文件
52+
*
5153
* \return FileType 文件类型
5254
*/
53-
FileType GetFileType(const std::string &file_path);
55+
FileType GetFileType(const std::string &file_path, bool refer_to_real_file = false);
5456

5557
/**
5658
* 检查文件是否存在

version.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
# TBOX版本号
2222
TBOX_VERSION_MAJOR := 1
2323
TBOX_VERSION_MINOR := 12
24-
TBOX_VERSION_REVISION := 14
24+
TBOX_VERSION_REVISION := 15

0 commit comments

Comments
 (0)