Commit 9508ea98 authored by Max Kellermann's avatar Max Kellermann

fs/Path: add method IsAbsolute()

parent 47d655ea
......@@ -118,7 +118,7 @@ ParsePath(const char *path, Error &error)
return Path::Null();
return Path::Build(home, path2);
} else if (!g_path_is_absolute(path)) {
} else if (!Path::IsAbsoluteUTF8(path)) {
error.Format(path_domain,
"not an absolute path: %s", path);
return Path::Null();
......
......@@ -153,7 +153,7 @@ decoder_file_decode(const struct decoder_plugin *plugin,
assert(decoder->stream_tag == NULL);
assert(decoder->decoder_tag == NULL);
assert(path != NULL);
assert(g_path_is_absolute(path));
assert(Path::IsAbsoluteFS(path));
assert(decoder->dc->state == DecoderState::START);
FormatDebug(decoder_thread_domain, "probing plugin %s", plugin->name);
......
......@@ -246,7 +246,7 @@ LoadPlaylistFile(const char *utf8path, Error &error)
if (!uri_has_scheme(s)) {
uri_utf8 = map_fs_to_utf8(s);
if (uri_utf8.empty()) {
if (g_path_is_absolute(s)) {
if (Path::IsAbsoluteFS(s)) {
uri_utf8 = Path::ToUTF8(s);
if (uri_utf8.empty())
continue;
......
......@@ -56,7 +56,7 @@ void
playlist_print_uri(FILE *file, const char *uri)
{
Path path = playlist_saveAbsolutePaths && !uri_has_scheme(uri) &&
!g_path_is_absolute(uri)
!Path::IsAbsoluteUTF8(uri)
? map_uri_fs(uri)
: Path::FromUTF8(uri);
......
......@@ -98,7 +98,7 @@ playlist_check_load_song(const Song *song, const char *uri, bool secure)
if (uri_has_scheme(uri)) {
dest = Song::NewRemote(uri);
} else if (g_path_is_absolute(uri) && secure) {
} else if (Path::IsAbsoluteUTF8(uri) && secure) {
dest = Song::LoadFile(uri, nullptr);
if (dest == nullptr)
return nullptr;
......@@ -147,7 +147,7 @@ playlist_check_translate_song(Song *song, const char *base_uri,
functions */
base_uri = nullptr;
if (g_path_is_absolute(uri)) {
if (Path::IsAbsoluteUTF8(uri)) {
/* XXX fs_charset vs utf8? */
const char *suffix = map_to_relative_path(uri);
assert(suffix != nullptr);
......
......@@ -28,6 +28,7 @@
#include "TextFile.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
#include "fs/Path.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -92,7 +93,7 @@ queue_load_song(TextFile &file, const char *line, queue *queue)
if (g_str_has_prefix(line, SONG_BEGIN)) {
const char *uri = line + sizeof(SONG_BEGIN) - 1;
if (!uri_has_scheme(uri) && !g_path_is_absolute(uri))
if (!uri_has_scheme(uri) && !Path::IsAbsoluteUTF8(uri))
return;
Error error;
......
......@@ -47,7 +47,7 @@ Song::LoadFile(const char *path_utf8, Directory *parent)
Song *song;
bool ret;
assert((parent == NULL) == g_path_is_absolute(path_utf8));
assert((parent == NULL) == Path::IsAbsoluteUTF8(path_utf8));
assert(!uri_has_scheme(path_utf8));
assert(strchr(path_utf8, '\n') == NULL);
......
......@@ -295,7 +295,7 @@ skip_symlink(const Directory *directory, const char *utf8_name)
const char *target_str = target.c_str();
if (g_path_is_absolute(target_str)) {
if (Path::IsAbsoluteFS(target_str)) {
/* if the symlink points to an absolute path, see if
that path is inside the music directory */
const char *relative = map_to_relative_path(target_str);
......
......@@ -23,6 +23,10 @@
#include "check.h"
#include "gcc.h"
#ifdef WIN32
#include <glib.h>
#endif
#include <algorithm>
#include <string>
......@@ -261,6 +265,33 @@ public:
#endif
ch == SEPARATOR_UTF8;
}
gcc_pure
static bool IsAbsoluteFS(const_pointer p) {
assert(p != nullptr);
#ifdef WIN32
return g_path_is_absolute(p);
#else
return IsSeparatorFS(*p);
#endif
}
gcc_pure
static bool IsAbsoluteUTF8(const char *p) {
assert(p != nullptr);
#ifdef WIN32
return g_path_is_absolute(p);
#else
return IsSeparatorUTF8(*p);
#endif
}
gcc_pure
bool IsAbsolute() {
return IsAbsoluteFS(c_str());
}
};
#endif
......@@ -26,6 +26,7 @@
#include "InputPlugin.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "fs/Path.hxx"
#include "Log.hxx"
#include <glib.h>
......@@ -49,7 +50,7 @@ input_archive_open(const char *pathname,
char *archive, *filename, *suffix, *pname;
struct input_stream *is;
if (!g_path_is_absolute(pathname))
if (!Path::IsAbsoluteFS(pathname))
return NULL;
pname = g_strdup(pathname);
......
......@@ -24,6 +24,7 @@
#include "InputPlugin.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "fs/Path.hxx"
#include "system/fd_util.h"
#include "open.h"
......@@ -62,7 +63,7 @@ input_file_open(const char *filename,
int fd, ret;
struct stat st;
if (!g_path_is_absolute(filename))
if (!Path::IsAbsoluteFS(filename))
return nullptr;
fd = open_cloexec(filename, O_RDONLY|O_BINARY, 0);
......
......@@ -34,6 +34,7 @@
#include "Song.hxx"
#include "TagFile.hxx"
#include "cue/CueParser.hxx"
#include "fs/Path.hxx"
#include <glib.h>
#include <assert.h>
......@@ -95,7 +96,7 @@ embcue_playlist_open_uri(const char *uri,
gcc_unused Mutex &mutex,
gcc_unused Cond &cond)
{
if (!g_path_is_absolute(uri))
if (!Path::IsAbsoluteUTF8(uri))
/* only local files supported */
return NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment