[DEV] support multiple acces when download a file

This commit is contained in:
Edouard DUPIN 2017-04-28 21:57:50 +02:00
parent 958060692c
commit 3ba5889541

View File

@ -158,15 +158,19 @@ namespace appl {
// //
} }
uint32_t add(zeus::ProxyFile _dataFile) override { uint32_t add(zeus::ProxyFile _dataFile) override {
{
std::unique_lock<std::mutex> lock(g_mutex); std::unique_lock<std::mutex> lock(g_mutex);
// TODO : Check right ... // TODO : Check right ...
uint64_t id = createUniqueID(); uint64_t id = createUniqueID();
}
auto futRemoteSha512 = _dataFile.getSha512(); auto futRemoteSha512 = _dataFile.getSha512();
auto futType = _dataFile.getMineType(); auto futType = _dataFile.getMineType();
auto futName = _dataFile.getName(); auto futName = _dataFile.getName();
// wait the sha1 to check his existance: // wait the sha1 to check his existance:
futRemoteSha512.wait(); futRemoteSha512.wait();
std::string sha512StringRemote = futRemoteSha512.get(); std::string sha512StringRemote = futRemoteSha512.get();
{
std::unique_lock<std::mutex> lock(g_mutex);
for (auto &it : m_listFile) { for (auto &it : m_listFile) {
if (it == nullptr) { if (it == nullptr) {
continue; continue;
@ -178,6 +182,7 @@ namespace appl {
return it->getUniqueId(); return it->getUniqueId();
} }
} }
}
std::string tmpFileName = g_basePath + "tmpImport_" + etk::to_string(id); std::string tmpFileName = g_basePath + "tmpImport_" + etk::to_string(id);
std::string sha512String = zeus::storeInFile(_dataFile, tmpFileName); std::string sha512String = zeus::storeInFile(_dataFile, tmpFileName);
futType.wait(); futType.wait();
@ -189,20 +194,23 @@ namespace appl {
throw std::runtime_error("file size == 0"); throw std::runtime_error("file size == 0");
} }
if (zeus::getExtention(futType.get()) != "") { if (zeus::getExtention(futType.get()) != "") {
std::unique_lock<std::mutex> lock(g_mutex);
etk::FSNodeMove(tmpFileName, g_basePath + sha512String + "." + zeus::getExtention(futType.get())); etk::FSNodeMove(tmpFileName, g_basePath + sha512String + "." + zeus::getExtention(futType.get()));
ememory::SharedPtr<zeus::MediaImpl> property = ememory::makeShared<zeus::MediaImpl>(id, sha512String + "." + zeus::getExtention(futType.get()), g_basePath); ememory::SharedPtr<zeus::MediaImpl> property = ememory::makeShared<zeus::MediaImpl>(id, sha512String + "." + zeus::getExtention(futType.get()), g_basePath);
property->setMetadata("sha512", sha512String); property->setMetadata("sha512", sha512String);
property->setMetadata("mime-type", futType.get()); property->setMetadata("mime-type", futType.get());
property->setCallbackMetadataChange(&metadataChange); property->setCallbackMetadataChange(&metadataChange);
m_listFile.push_back(property); m_listFile.push_back(property);
g_needToStore = true;
} else { } else {
std::unique_lock<std::mutex> lock(g_mutex);
etk::FSNodeMove(tmpFileName, g_basePath + sha512String); etk::FSNodeMove(tmpFileName, g_basePath + sha512String);
ememory::SharedPtr<zeus::MediaImpl> property = ememory::makeShared<zeus::MediaImpl>(id, sha512String, g_basePath); ememory::SharedPtr<zeus::MediaImpl> property = ememory::makeShared<zeus::MediaImpl>(id, sha512String, g_basePath);
property->setMetadata("sha512", sha512String); property->setMetadata("sha512", sha512String);
property->setCallbackMetadataChange(&metadataChange); property->setCallbackMetadataChange(&metadataChange);
m_listFile.push_back(property); m_listFile.push_back(property);
}
g_needToStore = true; g_needToStore = true;
}
APPL_DEBUG(" filename : " << sha512String); APPL_DEBUG(" filename : " << sha512String);
return id; return id;
} }