Skip to content

Commit

Permalink
Fixed file::isReadable.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed Feb 25, 2024
1 parent ca41591 commit b1f01e6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 32 deletions.
2 changes: 2 additions & 0 deletions mrv2/docs/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ v1.0.7
- Updated Python API with FFmpeg and Background changes.
- Fixed reading permissions on files as they were broken! I did not notice
as I was using an NTFS drive which sets umask 0022 by default.
- Made reading session more robust to handle missing files or wrong settings.
- Made checking for readable files faster.


v1.0.6
Expand Down
12 changes: 3 additions & 9 deletions mrv2/lib/mrvApp/mrvApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// mrv2
// Copyright Contributors to the mrv2 Project. All rights reserved.


#include <fstream>
#include <sstream>

Expand Down Expand Up @@ -410,8 +409,7 @@ namespace mrv
std::cout << std::endl
<< "mrv2 v" << mrv::version() << " " << mrv::build_date()
<< std::endl
<< mrv::get_os_version()
<< std::endl;
<< mrv::get_os_version() << std::endl;
return;
}

Expand Down Expand Up @@ -627,7 +625,6 @@ namespace mrv
}
});


p.logObserver = observer::ListObserver<log::Item>::create(
ui->app->getContext()->getLogSystem()->observeLog(),
[this](const std::vector<log::Item>& value)
Expand All @@ -654,7 +651,6 @@ namespace mrv
}
});


DBG;
cacheUpdate();
_audioUpdate();
Expand All @@ -666,8 +662,6 @@ namespace mrv
bool foundAudio = false;
for (const auto& fileName : p.options.fileNames)
{
if (fileName.empty())
continue;
if (file::isSequence(fileName) && !foundAudio)
{
open(fileName, p.options.audioFileName);
Expand Down Expand Up @@ -1443,8 +1437,8 @@ namespace mrv
auto Aitem = p.filesModel->observeA()->get();
if (Aitem && file::isTemporaryNDI(Aitem->path))
{
uint64_t NDIGbytes =
static_cast<uint64_t>(p.settings->getValue<int>("NDI/GBytes"));
uint64_t NDIGbytes = static_cast<uint64_t>(
p.settings->getValue<int>("NDI/GBytes"));
bytes = NDIGbytes * memory::gigabyte;
}
// Update the I/O cache.
Expand Down
38 changes: 19 additions & 19 deletions mrv2/lib/mrvCore/mrvFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// mrv2
// Copyright Contributors to the mrv2 Project. All rights reserved.

#include <fstream>
#include <filesystem>
namespace fs = std::filesystem;

Expand Down Expand Up @@ -115,31 +116,30 @@ namespace mrv

bool isReadable(const fs::path& p)
{
const std::string fileName = p.generic_string();
if (fileName.substr(0, 5) == "http:" ||
fileName.substr(0, 6) == "https:" ||
fileName.substr(0, 5) == "rtmp:" ||
fileName.substr(0, 4) == "rtp:")
const std::string filePath = p.generic_string();
if (filePath.empty())
return false;

if (filePath.substr(0, 5) == "http:" ||
filePath.substr(0, 6) == "https:" ||
filePath.substr(0, 5) == "rtmp:" ||
filePath.substr(0, 4) == "rtp:")
{
return true;
}

std::error_code ec; // For noexcept overload usage.
if (!fs::exists(p, ec) || fileName.empty())
return false;
auto perms = fs::status(p, ec).permissions();
if ((perms & fs::perms::owner_read) != fs::perms::none ||
(perms & fs::perms::group_read) != fs::perms::none ||
(perms & fs::perms::others_read) != fs::perms::none)
std::ifstream f(filePath);
if (f.is_open())
{
f.close();
return true;
}

return false;
}


static size_t ndiIndex = 1;

std::string NDI(ViewerUI* ui)
{
char buf[256];
Expand All @@ -156,8 +156,8 @@ namespace mrv
bool isTemporaryNDI(const tl::file::Path& path)
{
bool out = true;
const std::string tmpdir = tmppath() + '/';

const std::string tmpdir = tmppath() + '/';
auto dir = path.getDirectory();
auto base = path.getBaseName();
auto extension = path.getExtension();
Expand All @@ -168,11 +168,11 @@ namespace mrv
}
return out;
}

bool isTemporaryEDL(const tl::file::Path& path)
{
const std::string tmpdir = tmppath() + '/';

auto dir = path.getDirectory();
auto base = path.getBaseName();
auto extension = path.getExtension();
Expand All @@ -183,6 +183,6 @@ namespace mrv
}
return true;
}

} // namespace file
} // namespace mrv
19 changes: 15 additions & 4 deletions mrv2/lib/mrvFl/mrvSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ namespace mrv

// Copy annotations to both item and player
auto Aitem = model->observeA()->get();
if (!Aitem)
continue;

Aitem->annotations = item.annotations;
Aitem->videoLayer = item.videoLayer;
Aitem->currentTime = item.currentTime;
Expand Down Expand Up @@ -471,8 +474,11 @@ namespace mrv
// Handle color channel layer
//
int layer = session["layer"];
ui->uiColorChannel->value(layer);
ui->uiColorChannel->do_callback();
if (layer < ui->uiColorChannel->size())
{
ui->uiColorChannel->value(layer);
ui->uiColorChannel->do_callback();
}

//
// Handle OCIO
Expand Down Expand Up @@ -636,13 +642,18 @@ namespace mrv
{
ui->uiPrefs->uiPrefsAutoPlayback->value(autoplayback);

unsigned numFiles = model->observeFiles()->getSize();
int Aindex = session["Aindex"];
model->setA(Aindex);
if (Aindex < numFiles)
model->setA(Aindex);

std::vector<int> Bindexes = session["Bindexes"];
model->clearB();
for (auto i : Bindexes)
model->setB(i, true);
{
if (i < numFiles)
model->setB(i, true);
}

Message j = session["timeline"];

Expand Down

0 comments on commit b1f01e6

Please sign in to comment.