Fix delete directory
This commit is contained in:
@@ -181,6 +181,7 @@ public:
|
||||
_SiaApiError GetFileTree(std::shared_ptr<_CSiaFileTree>& siaFileTree) const;
|
||||
_SiaRenterAllowance GetAllowance() const;
|
||||
_SiaApiError SetAllowance(const _SiaRenterAllowance& renterAllowance);
|
||||
_SiaApiError RefreshFileTree( );
|
||||
};
|
||||
|
||||
class SIADRIVE_EXPORTABLE _CSiaConsensus :
|
||||
|
@@ -79,14 +79,11 @@ void CSiaApi::_CSiaRenter::Refresh(const CSiaCurl& siaCurl, CSiaDriveConfig* sia
|
||||
SetRenewWindow(renewWindow);
|
||||
SetPeriod(period);
|
||||
_currentAllowance = { funds, hosts, period, renewWindow };
|
||||
CSiaFileTreePtr fileTree(new CSiaFileTree(siaCurl, siaDriveConfig));
|
||||
if (ApiSuccess(siaCurl.Get(L"/renter/files", result)))
|
||||
{
|
||||
fileTree->BuildTree(result);
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_fileTreeMutex);
|
||||
_fileTree = fileTree;
|
||||
}
|
||||
|
||||
if (ApiSuccess(RefreshFileTree()))
|
||||
{
|
||||
CSiaFileTreePtr fileTree;
|
||||
GetFileTree(fileTree);
|
||||
|
||||
auto fileList = fileTree->GetFileList();
|
||||
if (fileList.size())
|
||||
@@ -129,6 +126,23 @@ void CSiaApi::_CSiaRenter::Refresh(const CSiaCurl& siaCurl, CSiaDriveConfig* sia
|
||||
}
|
||||
}
|
||||
|
||||
SiaApiError CSiaApi::_CSiaRenter::RefreshFileTree( )
|
||||
{
|
||||
SiaApiError ret = SiaApiError::RequestError;
|
||||
CSiaFileTreePtr tempTree(new CSiaFileTree(GetSiaCurl(), &GetSiaDriveConfig()));
|
||||
json result;
|
||||
if (ApiSuccess(GetSiaCurl().Get(L"/renter/files", result)))
|
||||
{
|
||||
tempTree->BuildTree(result);
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_fileTreeMutex);
|
||||
_fileTree = tempTree;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SiaApiError CSiaApi::_CSiaRenter::FileExists(const SString& siaPath, bool& exists) const
|
||||
{
|
||||
CSiaFileTreePtr siaFileTree;
|
||||
|
@@ -127,12 +127,7 @@ private:
|
||||
{
|
||||
do
|
||||
{
|
||||
CSiaFileTreePtr siaFileTree;
|
||||
_siaApi->GetRenter()->GetFileTree(siaFileTree);
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_fileTreeMutex);
|
||||
_siaFileTree = siaFileTree;
|
||||
}
|
||||
RefreshActiveFileTree();
|
||||
} while (::WaitForSingleObject(_fileListStopEvent, 1000) == WAIT_TIMEOUT);
|
||||
}));
|
||||
}
|
||||
@@ -149,6 +144,21 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
static void RefreshActiveFileTree(const bool& force = false)
|
||||
{
|
||||
if (force)
|
||||
{
|
||||
_siaApi->GetRenter()->RefreshFileTree();
|
||||
}
|
||||
|
||||
CSiaFileTreePtr siaFileTree;
|
||||
_siaApi->GetRenter()->GetFileTree(siaFileTree);
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_fileTreeMutex);
|
||||
_siaFileTree = siaFileTree;
|
||||
}
|
||||
}
|
||||
|
||||
// Dokan callbacks
|
||||
private:
|
||||
static NTSTATUS DOKAN_CALLBACK Sia_ZwCreateFile(
|
||||
@@ -183,7 +193,7 @@ private:
|
||||
{
|
||||
// When filePath is a directory, needs to change the flag so that the file can
|
||||
// be opened.
|
||||
FilePath cacheFilePath(GetCacheLocation(), &fileName[1]);
|
||||
FilePath cacheFilePath(GetCacheLocation(), fileName);
|
||||
DWORD fileAttr = ::GetFileAttributes(&cacheFilePath[0]);
|
||||
|
||||
if ((fileAttr != INVALID_FILE_ATTRIBUTES) &&
|
||||
@@ -211,7 +221,7 @@ private:
|
||||
}
|
||||
else if (creationDisposition == OPEN_ALWAYS)
|
||||
{
|
||||
if (cacheFilePath.CreateDirectory())
|
||||
if (!cacheFilePath.CreateDirectory())
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
if (error != ERROR_ALREADY_EXISTS)
|
||||
@@ -228,20 +238,22 @@ private:
|
||||
!(fileAttr & FILE_ATTRIBUTE_DIRECTORY) &&
|
||||
(createOptions & FILE_DIRECTORY_FILE))
|
||||
{
|
||||
return STATUS_NOT_A_DIRECTORY;
|
||||
}
|
||||
|
||||
// FILE_FLAG_BACKUP_SEMANTICS is required for opening directory handles
|
||||
HANDLE handle = ::CreateFile(&cacheFilePath[0], genericDesiredAccess, shareAccess, &securityAttrib, OPEN_EXISTING, fileAttributesAndFlags | FILE_FLAG_BACKUP_SEMANTICS, nullptr);
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
}
|
||||
else
|
||||
{
|
||||
dokanFileInfo->Context = reinterpret_cast<ULONG64>(handle); // save the file handle in Context
|
||||
ret = STATUS_NOT_A_DIRECTORY;
|
||||
}
|
||||
else
|
||||
{
|
||||
// FILE_FLAG_BACKUP_SEMANTICS is required for opening directory handles
|
||||
HANDLE handle = ::CreateFile(&cacheFilePath[0], genericDesiredAccess, shareAccess, &securityAttrib, OPEN_EXISTING, fileAttributesAndFlags | FILE_FLAG_BACKUP_SEMANTICS, nullptr);
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
ret = DokanNtStatusFromWin32(error);
|
||||
}
|
||||
else
|
||||
{
|
||||
dokanFileInfo->Context = reinterpret_cast<ULONG64>(handle); // save the file handle in Context
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else // File (cache and/or Sia operation)
|
||||
@@ -927,6 +939,7 @@ private:
|
||||
{
|
||||
}
|
||||
}
|
||||
RefreshActiveFileTree(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user