|
@@ -15,9 +15,10 @@ bool FileMan::isPutting() { return putfile.is_open(); }
|
|
|
|
|
|
bool FileMan::isListing() { return islisting; }
|
|
|
|
|
|
-bool FileMan::openPut(const std::string &name) {
|
|
|
- putname = name;
|
|
|
- putfile.open(name, std::ios::ate | std::ios::binary);
|
|
|
+bool FileMan::openPut(const std::string &path) {
|
|
|
+ putpath = path;
|
|
|
+ putname = pathToFilename(path);
|
|
|
+ putfile.open(path, std::ios::ate | std::ios::binary);
|
|
|
if (putfile.is_open()) {
|
|
|
size_t size = putfile.tellg();
|
|
|
putsize = size;
|
|
@@ -29,11 +30,12 @@ bool FileMan::openPut(const std::string &name) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-bool FileMan::openGet(const std::string &name) {
|
|
|
- getname = name;
|
|
|
+bool FileMan::openGet(const std::string &path) {
|
|
|
+ getpath = path;
|
|
|
+ getname = pathToFilename(path);
|
|
|
getchunks = 0;
|
|
|
getchunksRemaining = 0;
|
|
|
- getfile.open(name, std::ios::app | std::ios::binary);
|
|
|
+ getfile.open(path, std::ios::app | std::ios::binary);
|
|
|
if (getfile.tellp() != std::ios::beg) {
|
|
|
closeGet();
|
|
|
return false;
|
|
@@ -129,3 +131,26 @@ int FileMan::getPutSize() { return putsize; }
|
|
|
int FileMan::getListRemainingChunks() { return listchunksRemaining; }
|
|
|
|
|
|
int FileMan::getListChunks() { return listchunks; }
|
|
|
+
|
|
|
+std::string FileMan::pathToFilename(std::string path) {
|
|
|
+
|
|
|
+ int lastFoundIndex = -1;
|
|
|
+
|
|
|
+ for (int currentIndex = name.find("/"); currentIndex != string::npos;
|
|
|
+ currentIndex = name.find("/", currentIndex + 1)) {
|
|
|
+
|
|
|
+ // check if the "/" was escaped
|
|
|
+ if (currentIndex > 0 && cmd[currentIndex - 1] = '\\')
|
|
|
+ continue;
|
|
|
+
|
|
|
+ // check if the "/" is at the end of path name
|
|
|
+ if (currentIndex + 1 == name.length) {
|
|
|
+ // ERROR: INVALID FILENAME, BECAUSE ENDS WITH "/"
|
|
|
+ }
|
|
|
+
|
|
|
+ // otherwise we found a valid "/"
|
|
|
+ lastFoundIndex = currentIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+ return name.substr(lastFoundIndex + 1);
|
|
|
+}
|