// FullDestPath = HomePath + DestPath
// TODO(hdq): This depends on filesystem api?
const std::string GetFullDestinationPath(const std::string destination) const;
- const std::string GetRealLocation(const std::string& destination) const;
+ const std::string GetActualFolder(const std::string& destination) const;
bool GetDownloadID(const picojson::value& msg,
int& downloadID, DownloadArgs** args);
#include "download/download_context.h"
-const std::string DownloadContext::GetRealLocation(
+const std::string DownloadContext::GetActualFolder(
const std::string& destination) const {
typedef std::map<std::string, std::string> LocationMap;
static const LocationMap::value_type data[] = {
const std::string destination) const {
// TODO(hdq): User should be able to choose store to external storage
// i.e. /opt/storage/sdcard/Downloads
- std::string path("/opt/usr/media/");
- std::string location = destination;
- if (destination.empty()) {
- location = "Downloads";
- }
- std::string default_path = path+location;
- path += GetRealLocation(location);
+ const std::string directory("/opt/usr/media/");
+ const std::string default_folder("Downloads");
+ const std::string location = destination.empty() ? default_folder : destination;
+ std::string path = directory + GetActualFolder(location);
// Create path if not exist
struct stat path_stat;
- if (stat(path.c_str(), &path_stat) != -1
- || mkdir(path.c_str(), 0777) != 0) {
- path = default_path;
+ if (stat(path.c_str(), &path_stat) == -1
+ && mkdir(path.c_str(), 0777) != 0) {
+ path = directory + default_folder;
}
return path;