Changeset View
Changeset View
Standalone View
Standalone View
source/lib/file/file_system.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2022 Wildfire Games. | ||||
vladislavbelov: 2023. | |||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining | * Permission is hereby granted, free of charge, to any person obtaining | ||||
* a copy of this software and associated documentation files (the | * a copy of this software and associated documentation files (the | ||||
* "Software"), to deal in the Software without restriction, including | * "Software"), to deal in the Software without restriction, including | ||||
* without limitation the rights to use, copy, modify, merge, publish, | * without limitation the rights to use, copy, modify, merge, publish, | ||||
* distribute, sublicense, and/or sell copies of the Software, and to | * distribute, sublicense, and/or sell copies of the Software, and to | ||||
* permit persons to whom the Software is furnished to do so, subject to | * permit persons to whom the Software is furnished to do so, subject to | ||||
* the following conditions: | * the following conditions: | ||||
Show All 12 Lines | |||||
/* | /* | ||||
* higher-level interface on top of sysdep/filesystem.h | * higher-level interface on top of sysdep/filesystem.h | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "lib/file/file_system.h" | #include "lib/file/file_system.h" | ||||
#include <vector> | |||||
#include <algorithm> | |||||
#include <string> | |||||
#include "lib/sysdep/filesystem.h" | #include "lib/sysdep/filesystem.h" | ||||
#include "ps/CLogger.h" | |||||
#include <boost/filesystem.hpp> | #include <boost/filesystem.hpp> | ||||
#include <memory> | |||||
bool DirectoryExists(const OsPath& path) | bool DirectoryExists(const OsPath& path) | ||||
{ | { | ||||
WDIR* dir = wopendir(path); | WDIR* dir = wopendir(path); | ||||
if(dir) | if(dir) | ||||
{ | { | ||||
wclosedir(dir); | wclosedir(dir); | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | for(;;) | ||||
for(size_t i = 0; osEnt->d_name[i] != '\0'; i++) | for(size_t i = 0; osEnt->d_name[i] != '\0'; i++) | ||||
RETURN_STATUS_IF_ERR(Path::Validate(osEnt->d_name[i])); | RETURN_STATUS_IF_ERR(Path::Validate(osEnt->d_name[i])); | ||||
const OsPath name(osEnt->d_name); | const OsPath name(osEnt->d_name); | ||||
// get file information (mode, size, mtime) | // get file information (mode, size, mtime) | ||||
struct stat s; | struct stat s; | ||||
#if OS_WIN | #if OS_WIN | ||||
// .. return wdirent directly (much faster than calling stat). | // .. return wdirent directly (much faster than calling stat). | ||||
RETURN_STATUS_IF_ERR(wreaddir_stat_np(osDir.get(), &s)); | RETURN_STATUS_IF_ERR(wreaddir_stat_np(osDir.get(), &s)); | ||||
vladislavbelovUnsubmitted Not Done Inline ActionsWhat's about Windows? vladislavbelov: What's about Windows? | |||||
#else | #else | ||||
// .. call regular stat(). | // .. call regular stat(). | ||||
errno = 0; | errno = 0; | ||||
const OsPath pathname = path / name; | const OsPath pathname = path / name; | ||||
if(wstat(pathname, &s) != 0) | if(wstat(pathname, &s) != 0) | ||||
{ | |||||
if (errno == ENOENT) | |||||
vladislavbelovUnsubmitted Not Done Inline ActionsIf we skip such files doesn't it make sense to also ignore files without enough rights to read EACCES (maybe other errors too)? vladislavbelov: If we skip such files doesn't it make sense to also ignore files without enough rights to read… | |||||
phositAuthorUnsubmitted Done Inline ActionsThis is the wrong place to handle EACCES. Eighter none set errno or all set errno. phosit: This is the wrong place to handle EACCES. Eighter none set errno or all set errno.
But… | |||||
{ | |||||
LOGWARNING("%s is a dangling symbolic link", | |||||
(path / name).string8().c_str()); | |||||
vladislavbelovUnsubmitted Not Done Inline ActionsMight be GetDirectoryEntries called before g_Logger initialization? vladislavbelov: Might be `GetDirectoryEntries` called before `g_Logger` initialization? | |||||
phositAuthorUnsubmitted Done Inline Actionswe can't be shure about that until we remove g_Logger and pass it as argument. phosit: we can't be shure about that until we remove g_Logger and pass it as argument. | |||||
StanUnsubmitted Not Done Inline ActionsYou can check for g_Logger though. Stan: You can check for g_Logger though. | |||||
StanUnsubmitted Not Done Inline ActionsStan: EDIT: https://trac.wildfiregames.com/wiki/Coding_Conventions#Errorreporting | |||||
Done Inline ActionsMight want to use pathname to avoid duplication. vladislavbelov: Might want to use `pathname` to avoid duplication. | |||||
continue; | |||||
} | |||||
WARN_RETURN(StatusFromErrno()); | WARN_RETURN(StatusFromErrno()); | ||||
} | |||||
#endif | #endif | ||||
if(files && S_ISREG(s.st_mode)) | if(files && S_ISREG(s.st_mode)) | ||||
files->push_back(CFileInfo(name, s.st_size, s.st_mtime)); | files->push_back(CFileInfo(name, s.st_size, s.st_mtime)); | ||||
else if(subdirectoryNames && S_ISDIR(s.st_mode) && name != L"." && name != L"..") | else if(subdirectoryNames && S_ISDIR(s.st_mode) && name != L"." && name != L"..") | ||||
subdirectoryNames->push_back(name); | subdirectoryNames->push_back(name); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 103 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
2023.