Skip to content

Commit

Permalink
File database fixes
Browse files Browse the repository at this point in the history
* Fixed so file database handles relative paths (bumped file database version)
* Fixed so skips of copies still updates file database to make sure they are evicted last
  • Loading branch information
honkstar1 committed Feb 16, 2022
1 parent 74e061a commit 056085e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/EACopyClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace eacopy

enum : uint {
ClientMajorVersion = 1,
ClientMinorVersion = 12
ClientMinorVersion = 13
};

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions include/EACopyShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ class FileDatabase
bool findFileForDeltaCopy(WString& outFile, const FileKey& key);

void addToFilesHistory(const FileKey& key, const Hash& hash, const WString& fullFileName);
void removeFileHistory(const FileKey& key);
uint garbageCollect(uint maxHistory);

bool primeDirectory(const WString& directory, IOStats& ioStats, bool useRelativePath, bool flush);
Expand Down
8 changes: 7 additions & 1 deletion source/EACopyClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,12 @@ Client::processFile(LogContext& logContext, Connection* sourceConnection, Connec
logContext.resetLastError(); // We want to handle failing links as non-error and fallback to normal copying
useLinks = false; // and do not try linking again if copy also fails.. just let copy retry
}
}
}
else
{
// Remove from fileDatabase.. since file at location has either changed or does not exist anymore and we don't want to look here again
m_fileDatabase.removeFileHistory(key);
}
}
}

Expand Down Expand Up @@ -638,6 +643,7 @@ Client::processFile(LogContext& logContext, Connection* sourceConnection, Connec
{
if (existed) // If failure was because file existed, then we're good and can skip
{
addToDatabase();
reportSkip();
return true;
}
Expand Down
26 changes: 22 additions & 4 deletions source/EACopyShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,19 @@ FileDatabase::addToFilesHistory(const FileKey& key, const Hash& hash, const WStr
m_fileHashes[hash] = &rec;
}

void
FileDatabase::removeFileHistory(const FileKey& key)
{
ScopedCriticalSection cs(m_filesCs);
auto findIt = m_files.find(key);
if (findIt == m_files.end())
return;
FileRec& rec = findIt->second;
m_filesHistory.erase(rec.historyIt);
m_fileHashes.erase(rec.hash);
m_files.erase(findIt);
}

uint
FileDatabase::garbageCollect(uint maxHistory)
{
Expand Down Expand Up @@ -2478,7 +2491,7 @@ FileDatabase::primeWait(IOStats& ioStats)
return true;
}

constexpr u8 linkDbCookie[] = "eacopydb002";
constexpr u8 linkDbCookie[] = "eacopydb003";

void
FileDatabase::readFile(const wchar_t* fullPath, IOStats& ioStats)
Expand Down Expand Up @@ -2525,6 +2538,10 @@ FileDatabase::readFile(const wchar_t* fullPath, IOStats& ioStats)
if (fullNameLen+1 >= MaxPath)
return;

u16 keyLen;
if (!eacopy::readFile(fullPath, handle, &keyLen, sizeof(keyLen), read, ioStats) || read != sizeof(keyLen))
return;

u8 nameBuffer[MaxPath];
if (!eacopy::readFile(fullPath, handle, nameBuffer, fullNameLen, read, ioStats) || read != fullNameLen)
return;
Expand All @@ -2533,9 +2550,7 @@ FileDatabase::readFile(const wchar_t* fullPath, IOStats& ioStats)
nameBuffer[fullNameLen+1] = 0;
WString fullFileName = (wchar_t*)nameBuffer;

const wchar_t* fileName = fullFileName.c_str();
if (auto lastSlashIndex = fullFileName.find_last_of(L'\\'))
fileName += lastSlashIndex + 1;
const wchar_t* fileName = fullFileName.c_str() + fullFileName.size() - keyLen;

FileKey key { fileName };

Expand Down Expand Up @@ -2573,6 +2588,9 @@ FileDatabase::writeFile(const wchar_t* fullPath, IOStats& ioStats)
u16 nameLen = fullFileName.size() * 2; // wchar
if (!eacopy::writeFile(fullPath, handle, &nameLen, sizeof(nameLen), ioStats))
return;
u16 keyLen = key.name.size();
if (!eacopy::writeFile(fullPath, handle, &keyLen, sizeof(keyLen), ioStats))
return;
if (!eacopy::writeFile(fullPath, handle, fullFileName.c_str(), nameLen, ioStats))
return;
if (!eacopy::writeFile(fullPath, handle, &key.fileSize, sizeof(key.fileSize), ioStats))
Expand Down

0 comments on commit 056085e

Please sign in to comment.