1
0

Dokan changes

This commit is contained in:
Scott E. Graves
2017-02-11 19:42:51 -06:00
parent 6c57281055
commit 3c1dd68622
6 changed files with 221 additions and 131 deletions

View File

@@ -1,5 +1,6 @@
#include "stdafx.h"
#include "SiaApi.h"
#include <regex>
using namespace Sia::Api;
@@ -16,6 +17,24 @@ CSiaApi::~CSiaApi()
_wallet->Lock();
}
String CSiaApi::FormatToSiaPath(String path)
{
if (path.length())
{
std::replace(path.begin(), path.end(), '\\', '/');
std::wregex r(L"/+");
path = std::regex_replace(path, r, L"/");
while (path[0] == '/')
{
path = path.substr(1);
}
}
return path;
}
String CSiaApi::GetServerVersion() const
{
return _siaCurl.GetServerVersion();

View File

@@ -40,6 +40,8 @@ public:
public:
void BuildTree(const json& result);
bool FileExists(const String& siaPath) const;
};
class AFX_EXT_CLASS _CSiaWallet
@@ -100,6 +102,9 @@ private:
std::shared_ptr<_CSiaWallet> _wallet;
std::shared_ptr<_CSiaRenter> _renter;
public:
static String FormatToSiaPath(String path);
public:
std::shared_ptr<_CSiaWallet> GetWallet() const;
std::shared_ptr<_CSiaRenter> GetRenter() const;

View File

@@ -14,6 +14,11 @@ CSiaApi::_CSiaFileTree::~_CSiaFileTree()
}
bool CSiaApi::_CSiaFileTree::FileExists(const String& siaPath) const
{
return false;
}
void CSiaApi::_CSiaFileTree::BuildTree(const json& result)
{

View File

@@ -15,7 +15,13 @@ CSiaApi::_CSiaRenter::~_CSiaRenter()
SiaApiError CSiaApi::_CSiaRenter::FileExists(const String& siaPath, bool& exists) const
{
return SiaApiError::NotImplemented;
CSiaFileTreePtr siaFileTree;
SiaApiError ret = GetFileTree(siaFileTree);
if (API_SUCCESS(SiaApiError, ret))
{
exists = siaFileTree->FileExists(siaPath);
}
return ret;
}
SiaApiError CSiaApi::_CSiaRenter::DeleteFile(const String& siaPath)

View File

@@ -128,17 +128,26 @@ private:
ACCESS_MASK genericDesiredAccess = DokanMapStandardToGenericAccess(DesiredAccess);
NTSTATUS ret = STATUS_SUCCESS;
// Probably not going to happen, but just in case
if (PathIsUNC(FileName))
{
ret = STATUS_ILLEGAL_ELEMENT_ADDRESS;
}
else
{
bool isFile = (FileAttributes & FILE_NON_DIRECTORY_FILE);
DokanFileInfo->IsDirectory = !isFile;
if (isFile)
{
// Formulate Sia path and cache path
String siaPath = PathSkipRoot(FileName); // Strip drive letter to get Sia path
String siaPath = CSiaApi::FormatToSiaPath(PathSkipRoot(FileName)); // Strip drive letter to get Sia path
if (siaPath.length())
{
String cacheFilePath;
cacheFilePath.resize(MAX_PATH + 1);
PathCombine(&cacheFilePath[0], _cacheLocation.c_str(), siaPath.c_str());
// If cache file already exists and is a directory, requested file operation doesn't make sense
// If cache file already exists and is a directory, requested file operation isn't valid
if (GetFileAttributes(cacheFilePath.c_str()) & FILE_ATTRIBUTE_DIRECTORY)
{
ret = STATUS_OBJECT_NAME_COLLISION;
@@ -289,10 +298,16 @@ private:
}
}
}
else
{
ret = STATUS_OBJECT_NAME_INVALID;
}
}
else // Folder Operation (cache operation only)
{
ret = STATUS_NOT_IMPLEMENTED;
}
}
return ret;
}

View File

@@ -20,6 +20,46 @@ namespace UnitTests
CSiaApi api(_hostConfig);
Assert::IsTrue(api.GetServerVersion() == TEST_SERVER_VERSION);
}
TEST_METHOD(RelativePathToSiaPath)
{
String relPath = L"test\\moose\\cow.txt";
String siaPath = CSiaApi::FormatToSiaPath(relPath);
Assert::AreEqual(L"test/moose/cow.txt", siaPath.c_str());
}
TEST_METHOD(RelativePathWithBeginningBackslashToSiaPath)
{
String relPath = L"\\test\\moose\\cow.txt";
String siaPath = CSiaApi::FormatToSiaPath(relPath);
Assert::AreEqual(L"test/moose/cow.txt", siaPath.c_str());
}
TEST_METHOD(RelativePathWithBeginningBackslashOnlyToSiaPath)
{
String relPath = L"\\";
String siaPath = CSiaApi::FormatToSiaPath(relPath);
Assert::AreEqual(L"", siaPath.c_str());
}
TEST_METHOD(FilenameOnlyToSiaPath)
{
String relPath = L"moose.txt";
String siaPath = CSiaApi::FormatToSiaPath(relPath);
Assert::AreEqual(L"moose.txt", siaPath.c_str());
}
TEST_METHOD(RemoveExtraBackslashes)
{
String relPath = L"\\\\\\\\test\\\\\\\\\\\\\\\\\\moose\\\\\\\\\\\\cow.txt";
String siaPath = CSiaApi::FormatToSiaPath(relPath);
Assert::AreEqual(L"test/moose/cow.txt", siaPath.c_str());
}
};
DEFINE_DAEMON(SiaApi);