2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2014-10-02 21:06:01 +02:00
|
|
|
|
|
|
|
#include "LocalOpen.hxx"
|
|
|
|
#include "InputStream.hxx"
|
|
|
|
#include "plugins/FileInputPlugin.hxx"
|
2018-11-19 12:49:45 +01:00
|
|
|
#include "config.h"
|
2014-10-02 21:06:01 +02:00
|
|
|
|
2020-05-05 15:32:41 +02:00
|
|
|
#include "io/uring/Features.h"
|
|
|
|
#ifdef HAVE_URING
|
|
|
|
#include "plugins/UringInputPlugin.hxx"
|
|
|
|
#endif
|
|
|
|
|
2014-10-02 21:06:01 +02:00
|
|
|
#ifdef ENABLE_ARCHIVE
|
|
|
|
#include "plugins/ArchiveInputPlugin.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "fs/Path.hxx"
|
2016-09-09 15:37:06 +02:00
|
|
|
#include "system/Error.hxx"
|
2014-10-02 21:06:01 +02:00
|
|
|
|
2020-03-12 23:20:59 +01:00
|
|
|
#include <cassert>
|
2014-10-02 21:06:01 +02:00
|
|
|
|
2016-02-21 08:03:32 +01:00
|
|
|
InputStreamPtr
|
2018-06-22 19:37:18 +02:00
|
|
|
OpenLocalInputStream(Path path, Mutex &mutex)
|
2014-10-02 21:06:01 +02:00
|
|
|
{
|
2016-09-09 15:37:06 +02:00
|
|
|
InputStreamPtr is;
|
2014-10-02 21:06:01 +02:00
|
|
|
|
|
|
|
#ifdef ENABLE_ARCHIVE
|
2016-09-09 15:37:06 +02:00
|
|
|
try {
|
|
|
|
#endif
|
2020-05-05 15:32:41 +02:00
|
|
|
#ifdef HAVE_URING
|
|
|
|
is = OpenUringInputStream(path.c_str(), mutex);
|
|
|
|
if (is)
|
|
|
|
return is;
|
|
|
|
#endif
|
|
|
|
|
2018-06-22 19:37:18 +02:00
|
|
|
is = OpenFileInputStream(path, mutex);
|
2016-09-09 15:37:06 +02:00
|
|
|
#ifdef ENABLE_ARCHIVE
|
|
|
|
} catch (const std::system_error &e) {
|
|
|
|
if (IsPathNotFound(e)) {
|
|
|
|
/* ENOTDIR means this may be a path inside an archive
|
|
|
|
file */
|
2018-06-22 19:37:18 +02:00
|
|
|
is = OpenArchiveInputStream(path, mutex);
|
2016-09-09 15:37:06 +02:00
|
|
|
if (!is)
|
|
|
|
throw;
|
|
|
|
} else
|
|
|
|
throw;
|
2014-10-02 21:17:31 +02:00
|
|
|
}
|
2014-10-02 21:06:01 +02:00
|
|
|
#endif
|
|
|
|
|
2018-01-20 19:15:51 +01:00
|
|
|
assert(is);
|
|
|
|
assert(is->IsReady());
|
2014-10-02 21:06:01 +02:00
|
|
|
|
|
|
|
return is;
|
|
|
|
}
|