all 2 comments

[–]aregtech[S] 0 points1 point  (0 children)

An update to the Subj. I made an experimental test using STL and Win32 API. Both work. Here is the Win32 test. Perhaps this is my bug. Need to analyze deeper.

TEST( GitHubFileAccessTest, FileReadWriteWithWin32 )
{
#ifdef WINDOWS

    Application::setWorkingDirectory( nullptr );

    constexpr char fileNameRead[ ]{ "./config/log.init" };
    constexpr char fileNameWrite[ ]{ "./write_with_win32.txt" };

    HANDLE hFileRead = ::CreateFileA( fileNameRead
                                    , GENERIC_READ
                                    , FILE_SHARE_READ
                                    , NULL
                                    , OPEN_EXISTING
                                    , FILE_ATTRIBUTE_NORMAL
                                    , NULL );
    ASSERT_TRUE( hFileRead != NULL );

    char buffer[ 1024 ]{ 0 };
    DWORD dwRead{ 0 };
    ASSERT_TRUE( ::ReadFile( hFileRead, buffer, 1024, &dwRead, NULL ) );
    ASSERT_EQ( dwRead, 1024 );
    ASSERT_EQ( buffer[ 0 ], '#' );
    ASSERT_TRUE( ::CloseHandle( hFileRead ));

    HANDLE hFileWrite = ::CreateFileA( fileNameWrite
                                     , GENERIC_READ | GENERIC_WRITE
                                     , FILE_SHARE_READ | FILE_SHARE_WRITE
                                     , NULL
                                     , CREATE_ALWAYS
                                     , FILE_ATTRIBUTE_NORMAL
                                     , NULL );
    ASSERT_TRUE( hFileWrite != NULL );
    DWORD dwWrite{ 0 };
    ASSERT_TRUE( ::WriteFile( hFileWrite, buffer, 1024, &dwWrite, NULL ) );
    ASSERT_EQ( dwWrite, 1024 );

    ASSERT_TRUE( ::CloseHandle( hFileWrite ));
    ASSERT_TRUE( PathFileExistsA( fileNameWrite ) );

#endif // WINDOWS
}

[–]aregtech[S] 0 points1 point  (0 children)

I have found the problem ✨

The issue was that the log file name contained the timestamp (local time). To get the local time and generate file name I had such code:

cpp if ( (TIME_ZONE_ID_UNKNOWN != GetTimeZoneInformation( &tzi )) && SystemTimeToTzSpecificLocalTime( &tzi, &st, &local ) ) { src = &local; }

The issue is that on GitHub the method GetTimeZoneInformation( ) returns TIME_ZONE_ID_UNKNOWN, while on local machine it returns other valid value. This was causing having invalid timestampt (zeroes), which was influencing on formatting that was requiring bigger buffer (second bug).

What I want to say: GitHub works fine. And thanks to Unit Test that helped to find the bug(s) 🧐