Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File size and creation time are not shown if the path contains non-English letters #202

Open
MurlokotomkaOriginal opened this issue Nov 26, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@MurlokotomkaOriginal
Copy link

MurlokotomkaOriginal commented Nov 26, 2024

To solve the problem I fixed the function "m_CompleteFileInfos"

void IGFD::FileManager::m_CompleteFileInfos(const std::shared_ptr<FileInfos>& vInfos) {
    if (!vInfos.use_count()) return;

    if (!vInfos && vInfos->fileNameExt != "." && vInfos->fileNameExt != "..") {

        std::string fpn;

        // FIXME: so the condition is always true?
        if (vInfos->fileType.isFile() || vInfos->fileType.isLinkToUnknown() || vInfos->fileType.isDir()) {
            fpn = vInfos->filePath + IGFD::Utils::GetPathSeparator() + vInfos->fileNameExt;
        }

        namespace fs = std::filesystem;
        fs::path filePath(fpn);
        try 
        {
            if (!vInfos->fileType.isDir()) 
            {
                vInfos->fileSize = (size_t)fs::file_size(filePath);
                vInfos->formatedFileSize = IGFD::Utils::FormatFileSize(vInfos->fileSize);
            }
            size_t len = 0;
            auto lastWriteTime = fs::last_write_time(filePath);
            auto cftime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now() + (lastWriteTime - fs::file_time_type::clock::now()));
            char timebuf[100];
            std::strftime(timebuf, sizeof(timebuf), DateTimeFormat, std::localtime(&cftime));
            vInfos->fileModifDate = timebuf;
        }
        catch (const fs::filesystem_error& e)
        {
            vInfos->fileSize = 0;
            vInfos->formatedFileSize = "0 B";
            vInfos->fileModifDate = "Unknown";
        }
    }
}
@aiekick aiekick added the bug Something isn't working label Nov 26, 2024
@aiekick
Copy link
Owner

aiekick commented Nov 26, 2024

Hello,

thanks for the feedback.

btw you cant use std::filesystem like that, since this lib is agnostic for the filesystem api.

and can you explain what was the bug, and what is you solution ?

Thanks

@MurlokotomkaOriginal
Copy link
Author

Folders or files with utf-8 non-English letters in their paths do not show size and time of creation (columns show empty string). The stat function does not handle such paths correctly. In the original line "int result = stat(fpn.c_str(), &statInfos);" if fpn contains utf-8 non-English letters, then the size and time of file creation are not written to the statInfos structure

@MurlokotomkaOriginal
Copy link
Author

Line "if (!vInfos && vInfos->fileNameExt != "." && vInfos->fileNameExt != "..") {" incorrect in my original post. Used "if (vInfos->fileNameExt != "." && vInfos->fileNameExt != "..") {"

@aiekick
Copy link
Owner

aiekick commented Nov 27, 2024

ok so this is why you dont use stat in your solution and play with std::filesystem.
will search for a robust fix. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants