mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Core: Fixed problems with handling non-existent files
This commit is contained in:
parent
7905048239
commit
1a0922b860
7 changed files with 97 additions and 8 deletions
|
|
@ -28,6 +28,11 @@ void BlockStream::SetBufferSize(dword size)
|
|||
Seek(p);
|
||||
}
|
||||
|
||||
void BlockStream::Reset()
|
||||
{
|
||||
streamsize = pos = 0;
|
||||
}
|
||||
|
||||
BlockStream::BlockStream()
|
||||
{
|
||||
buffer = NULL;
|
||||
|
|
@ -40,13 +45,13 @@ BlockStream::~BlockStream()
|
|||
}
|
||||
|
||||
int64 BlockStream::GetSize() const {
|
||||
if(IsError()) return 0;
|
||||
if(IsError() || !ptr) return 0;
|
||||
return max(streamsize, ptr - buffer + pos);
|
||||
}
|
||||
|
||||
void BlockStream::SyncSize()
|
||||
{
|
||||
streamsize = max(streamsize, ptr - buffer + pos);
|
||||
streamsize = ptr ? max(streamsize, ptr - buffer + pos) : 0;
|
||||
}
|
||||
|
||||
void BlockStream::Flush() {
|
||||
|
|
@ -367,6 +372,7 @@ void FileStream::Close() {
|
|||
SetLastError();
|
||||
}
|
||||
handle = INVALID_HANDLE_VALUE;
|
||||
Reset();
|
||||
}
|
||||
|
||||
bool FileStream::IsOpen() const {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ int Compare_FileTime(const FileTime& fa, const FileTime& fb);
|
|||
#ifdef PLATFORM_WIN32
|
||||
|
||||
struct FileTime : FILETIME, CompareRelOps<const FileTime&, &Compare_FileTime> {
|
||||
FileTime() {}
|
||||
operator bool() const { return dwLowDateTime || dwHighDateTime; }
|
||||
FileTime() { dwLowDateTime = 0; dwHighDateTime = 0; }
|
||||
FileTime(const FILETIME& ft) { dwLowDateTime = ft.dwLowDateTime;
|
||||
dwHighDateTime = ft.dwHighDateTime; }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -383,6 +383,7 @@ public:
|
|||
virtual ~BlockStream();
|
||||
|
||||
protected:
|
||||
void Reset();
|
||||
void OpenInit(dword mode, int64 file_size);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -437,11 +437,15 @@ void Time::Serialize(Stream& s)
|
|||
#ifdef PLATFORM_WIN32
|
||||
Time::Time(FileTime filetime)
|
||||
{
|
||||
SYSTEMTIME tm, tml;
|
||||
FileTime ft;
|
||||
FileTimeToSystemTime(&filetime, &tm);
|
||||
SystemTimeToTzSpecificLocalTime(NULL, &tm, &tml);
|
||||
*this = Time(tml.wYear, tml.wMonth, tml.wDay, tml.wHour, tml.wMinute, tml.wSecond);
|
||||
if(filetime) {
|
||||
SYSTEMTIME tm, tml;
|
||||
FileTime ft;
|
||||
FileTimeToSystemTime(&filetime, &tm);
|
||||
SystemTimeToTzSpecificLocalTime(NULL, &tm, &tml);
|
||||
*this = Time(tml.wYear, tml.wMonth, tml.wDay, tml.wHour, tml.wMinute, tml.wSecond);
|
||||
}
|
||||
else
|
||||
*this = Null;
|
||||
}
|
||||
|
||||
FileTime Time::AsFileTime() const
|
||||
|
|
|
|||
35
upptst/InvalidFile/InvalidFile.cpp
Normal file
35
upptst/InvalidFile/InvalidFile.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
StdLogSetup(LOG_COUT|LOG_FILE);
|
||||
DDUMP(FileGetTime("asfasdfasdfasdf"));
|
||||
DDUMP(IsNull(FileGetTime("asfasdfasdfasdf")));
|
||||
DLOG("================");
|
||||
for(int pass = 0; pass < 2; pass++) {
|
||||
FileIn in;
|
||||
if(pass) {
|
||||
DLOG("==== Opening nonexistent file");
|
||||
in.Open("aklsdflkasljkdf");
|
||||
}
|
||||
|
||||
bool second = false;
|
||||
for(;;) {
|
||||
DDUMP((bool)in);
|
||||
DDUMP(in.IsEof());
|
||||
DDUMP(in.IsError());
|
||||
DDUMP(in.GetPos());
|
||||
DDUMP(in.GetSize());
|
||||
DDUMP(in.Get());
|
||||
if(second)
|
||||
break;
|
||||
second = true;
|
||||
DLOG("--- Seek 0");
|
||||
in.Seek(0);
|
||||
}
|
||||
}
|
||||
|
||||
CheckLogEtalon();
|
||||
}
|
||||
10
upptst/InvalidFile/InvalidFile.upp
Normal file
10
upptst/InvalidFile/InvalidFile.upp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
uses
|
||||
Core;
|
||||
|
||||
file
|
||||
InvalidFile.cpp,
|
||||
etalon.log;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
32
upptst/InvalidFile/etalon.log
Normal file
32
upptst/InvalidFile/etalon.log
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
* C:\upp\out\upptst\CLANGx64.Debug.Debug_Full\InvalidFile.exe 23.11.2024 11:51:22, user: cxl
|
||||
|
||||
FileGetTime("asfasdfasdfasdf") =
|
||||
IsNull(FileGetTime("asfasdfasdfasdf")) = true
|
||||
================
|
||||
(bool)in = false
|
||||
in.IsEof() = true
|
||||
in.IsError() = false
|
||||
in.GetPos() = 0
|
||||
in.GetSize() = 0
|
||||
in.Get() = -1
|
||||
--- Seek 0
|
||||
(bool)in = false
|
||||
in.IsEof() = true
|
||||
in.IsError() = false
|
||||
in.GetPos() = 0
|
||||
in.GetSize() = 0
|
||||
in.Get() = -1
|
||||
==== Opening nonexistent file
|
||||
(bool)in = false
|
||||
in.IsEof() = true
|
||||
in.IsError() = true
|
||||
in.GetPos() = 0
|
||||
in.GetSize() = 0
|
||||
in.Get() = -1
|
||||
--- Seek 0
|
||||
(bool)in = false
|
||||
in.IsEof() = true
|
||||
in.IsError() = true
|
||||
in.GetPos() = 0
|
||||
in.GetSize() = 0
|
||||
in.Get() = -1
|
||||
Loading…
Add table
Add a link
Reference in a new issue