1
0

Fix move file

This commit is contained in:
Scott E. Graves
2017-04-06 13:06:44 -05:00
parent 8834eb76d2
commit dd4b93693b
4 changed files with 56 additions and 40 deletions

View File

@@ -177,12 +177,13 @@ public:
void Refresh(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig);
public:
CSiaError<_SiaApiErrorCode> FileExists(const SString& siaPath, bool& exists) const;
CSiaError<_SiaApiErrorCode> DownloadFile(const SString& siaPath, const SString& location) const;
CSiaError<_SiaApiErrorCode> GetFileTree(std::shared_ptr<_CSiaFileTree>& siaFileTree) const;
CSiaError<_SiaApiErrorCode> FileExists(const SString& siaPath, bool& exists) const;
_SiaRenterAllowance GetAllowance() const;
CSiaError<_SiaApiErrorCode> SetAllowance(const _SiaRenterAllowance& renterAllowance);
CSiaError<_SiaApiErrorCode> GetFileTree(std::shared_ptr<_CSiaFileTree>& siaFileTree) const;
CSiaError<_SiaApiErrorCode> RefreshFileTree( );
CSiaError<_SiaApiErrorCode> RenameFile(const SString& siaPath, const SString& newSiaPath);
CSiaError<_SiaApiErrorCode> SetAllowance(const _SiaRenterAllowance& renterAllowance);
};
class SIADRIVE_EXPORTABLE _CSiaConsensus :

View File

@@ -685,10 +685,11 @@ class SIADRIVE_DOKAN_EXPORTABLE DokanMoveFileW :
public CEvent
{
public:
DokanMoveFileW(const SString& srcPath, const SString& destPath) :
DokanMoveFileW(const SString& srcPath, const SString& destPath, const NTSTATUS& result) :
CEvent(EventLevel::Debug),
_srcPath(srcPath),
_destPath(destPath)
_destPath(destPath),
_result(result)
{
}
@@ -700,16 +701,19 @@ public:
private:
const SString _srcPath;
const SString _destPath;
const NTSTATUS _result;
public:
virtual std::shared_ptr<CEvent> Clone() const override
{
return std::shared_ptr<CEvent>(new DokanMoveFileW(_srcPath, _destPath));
return std::shared_ptr<CEvent>(new DokanMoveFileW(_srcPath, _destPath, _result));
}
virtual SString GetSingleLineMessage() const override
{
return L"DokanMoveFileW|SRC|" + _srcPath + "|DEST|" + _destPath;
return L"DokanMoveFileW|SRC|" + _srcPath +
"|DEST|" + _destPath +
"|RES|" + SString::FromUInt64(_result);
}
};
NS_END(3)

View File

@@ -155,6 +155,19 @@ SiaApiError CSiaApi::_CSiaRenter::RefreshFileTree( )
return ret;
}
SiaApiError CSiaApi::_CSiaRenter::RenameFile(const SString& siaPath, const SString& newSiaPath)
{
SiaApiError ret;
json result;
SiaCurlError cerror = GetSiaCurl().Get(L"/renter/rename/" + siaPath, { { L"newsiapath", newSiaPath } }, result);
if (!ApiSuccess(cerror))
{
ret = { SiaApiErrorCode::RequestError, cerror.GetReason() };
}
return ret;
}
SiaApiError CSiaApi::_CSiaRenter::FileExists(const SString& siaPath, bool& exists) const
{
CSiaFileTreePtr siaFileTree;

View File

@@ -118,26 +118,18 @@ private:
static void HandleSiaFileClose(const OpenFileInfo& openFileInfo, const std::uint64_t& fileSize, const bool& deleteOnClose)
{
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanCloseFile(openFileInfo.CacheFilePath)));
if (deleteOnClose)
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanCloseFile(openFileInfo.CacheFilePath)));
if (deleteOnClose)
{
// TODO Handle failure
::CloseHandle(openFileInfo.FileHandle);
_uploadManager->Remove(openFileInfo.SiaPath);
}
else if (openFileInfo.Changed)
{
if (fileSize > 0)
{
// TODO Handle failure
::CloseHandle(openFileInfo.FileHandle);
_uploadManager->Remove(openFileInfo.SiaPath);
}
else
{
QueueUploadIfChanged(openFileInfo, fileSize);
}
}
static void QueueUploadIfChanged(const OpenFileInfo& openFileInfo, const std::uint64_t& size)
{
if (openFileInfo.Changed)
{
if (size > 0)
{
// TODO Handle error return
// TODO Handle error return
// Retrieve the file times for the file.
FILETIME fileTimes[3];
if (GetFileTime(openFileInfo.FileHandle, &fileTimes[0], &fileTimes[1], &fileTimes[2]))
@@ -149,20 +141,20 @@ private:
{
::CloseHandle(openFileInfo.FileHandle);
}
}
else
{
}
else
{
::CloseHandle(openFileInfo.FileHandle);
// TODO Handle error return
// Treat 0 length files as deleted in Sia - cache retains 0-length
_uploadManager->Remove(openFileInfo.SiaPath);
}
}
// Treat 0 length files as deleted in Sia - cache retains 0-length
_uploadManager->Remove(openFileInfo.SiaPath);
}
}
else
{
::CloseHandle(openFileInfo.FileHandle);
}
}
}
static void StartFileListThread()
{
@@ -666,7 +658,7 @@ private:
if (ret == STATUS_SUCCESS)
{
if (openFileInfo && openFileInfo->Dummy)
if ((openFileInfo && openFileInfo->Dummy) || (siaFile && !FilePath(cachFileLocation).IsFile()))
{
LARGE_INTEGER li = { 0 };
li.QuadPart = siaFile->GetFileSize();
@@ -1057,6 +1049,7 @@ private:
{
LARGE_INTEGER li = { 0 };
::GetFileSizeEx(openFileInfo->FileHandle, &li);
// !!! File handle will be closed in this method !!!
HandleSiaFileClose(*openFileInfo, li.QuadPart, dokanFileInfo->DeleteOnClose ? true : false);
}
@@ -1070,6 +1063,7 @@ private:
// if open with FILE_FLAG_DELETE_ON_CLOSE
if (dokanFileInfo->IsDirectory)
{
// TODO Add event notification
if (filePath.RemoveDirectory())
{
}
@@ -1153,7 +1147,6 @@ private:
static NTSTATUS DOKAN_CALLBACK Sia_DeleteFileW(LPCWSTR fileName, PDOKAN_FILE_INFO dokanFileInfo)
{
// TODO Check dummy and add to cache if not found
NTSTATUS ret = STATUS_SUCCESS;
auto openFileInfo = reinterpret_cast<OpenFileInfo*>(dokanFileInfo->Context);
@@ -1180,13 +1173,10 @@ private:
static NTSTATUS DOKAN_CALLBACK Sia_MoveFileW(LPCWSTR fileName, LPCWSTR NewFileName, BOOL ReplaceIfExisting, PDOKAN_FILE_INFO dokanFileInfo)
{
// TODO Check dummy and add to cache if not found
// TODO Implement Sia rename
NTSTATUS ret = STATUS_SUCCESS;
FilePath filePath(GetCacheLocation(), fileName);
FilePath newFilePath(GetCacheLocation(), NewFileName);
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanMoveFileW(filePath, newFilePath)));
auto openFileInfo = reinterpret_cast<OpenFileInfo*>(dokanFileInfo->Context);
if (!openFileInfo || !openFileInfo->FileHandle || (openFileInfo->FileHandle == INVALID_HANDLE_VALUE))
@@ -1212,7 +1202,14 @@ private:
BOOL result = ::SetFileInformationByHandle(openFileInfo->FileHandle, FileRenameInfo, renameInfo, bufferSize);
free(renameInfo);
if (!result)
if (result)
{
if (!ApiSuccess(_siaApi->GetRenter()->RenameFile(openFileInfo->SiaPath, CSiaApi::FormatToSiaPath(NewFileName))))
{
ret = STATUS_INTERNAL_ERROR;
}
}
else
{
DWORD error = GetLastError();
ret = DokanNtStatusFromWin32(error);
@@ -1224,6 +1221,7 @@ private:
}
}
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanMoveFileW(filePath, newFilePath, ret)));
return ret;
}