[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,24 +158,29 @@ namespace appl {
// //
} }
uint32_t add(zeus::ProxyFile _dataFile) override { uint32_t add(zeus::ProxyFile _dataFile) override {
std::unique_lock<std::mutex> lock(g_mutex); {
// TODO : Check right ... std::unique_lock<std::mutex> lock(g_mutex);
uint64_t id = createUniqueID(); // TODO : Check right ...
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();
for (auto &it : m_listFile) { {
if (it == nullptr) { std::unique_lock<std::mutex> lock(g_mutex);
continue; for (auto &it : m_listFile) {
} if (it == nullptr) {
if (it->getSha512() == sha512StringRemote) { continue;
APPL_INFO("File already registered at ");// << it.m_creationData); }
// simply send the Id of the file if (it->getSha512() == sha512StringRemote) {
// TODO : Check right of this file ... APPL_INFO("File already registered at ");// << it.m_creationData);
return it->getUniqueId(); // simply send the Id of the file
// TODO : Check right of this file ...
return it->getUniqueId();
}
} }
} }
std::string tmpFileName = g_basePath + "tmpImport_" + etk::to_string(id); std::string tmpFileName = g_basePath + "tmpImport_" + etk::to_string(id);
@ -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;
} }