fs/Path: add method IsAbsolute()

This commit is contained in:
Max Kellermann 2013-10-14 22:38:29 +02:00
parent 47d655ea7f
commit 9508ea982b
12 changed files with 47 additions and 12 deletions

View File

@ -118,7 +118,7 @@ ParsePath(const char *path, Error &error)
return Path::Null(); return Path::Null();
return Path::Build(home, path2); return Path::Build(home, path2);
} else if (!g_path_is_absolute(path)) { } else if (!Path::IsAbsoluteUTF8(path)) {
error.Format(path_domain, error.Format(path_domain,
"not an absolute path: %s", path); "not an absolute path: %s", path);
return Path::Null(); return Path::Null();

View File

@ -153,7 +153,7 @@ decoder_file_decode(const struct decoder_plugin *plugin,
assert(decoder->stream_tag == NULL); assert(decoder->stream_tag == NULL);
assert(decoder->decoder_tag == NULL); assert(decoder->decoder_tag == NULL);
assert(path != NULL); assert(path != NULL);
assert(g_path_is_absolute(path)); assert(Path::IsAbsoluteFS(path));
assert(decoder->dc->state == DecoderState::START); assert(decoder->dc->state == DecoderState::START);
FormatDebug(decoder_thread_domain, "probing plugin %s", plugin->name); FormatDebug(decoder_thread_domain, "probing plugin %s", plugin->name);

View File

@ -246,7 +246,7 @@ LoadPlaylistFile(const char *utf8path, Error &error)
if (!uri_has_scheme(s)) { if (!uri_has_scheme(s)) {
uri_utf8 = map_fs_to_utf8(s); uri_utf8 = map_fs_to_utf8(s);
if (uri_utf8.empty()) { if (uri_utf8.empty()) {
if (g_path_is_absolute(s)) { if (Path::IsAbsoluteFS(s)) {
uri_utf8 = Path::ToUTF8(s); uri_utf8 = Path::ToUTF8(s);
if (uri_utf8.empty()) if (uri_utf8.empty())
continue; continue;

View File

@ -56,7 +56,7 @@ void
playlist_print_uri(FILE *file, const char *uri) playlist_print_uri(FILE *file, const char *uri)
{ {
Path path = playlist_saveAbsolutePaths && !uri_has_scheme(uri) && Path path = playlist_saveAbsolutePaths && !uri_has_scheme(uri) &&
!g_path_is_absolute(uri) !Path::IsAbsoluteUTF8(uri)
? map_uri_fs(uri) ? map_uri_fs(uri)
: Path::FromUTF8(uri); : Path::FromUTF8(uri);

View File

@ -98,7 +98,7 @@ playlist_check_load_song(const Song *song, const char *uri, bool secure)
if (uri_has_scheme(uri)) { if (uri_has_scheme(uri)) {
dest = Song::NewRemote(uri); dest = Song::NewRemote(uri);
} else if (g_path_is_absolute(uri) && secure) { } else if (Path::IsAbsoluteUTF8(uri) && secure) {
dest = Song::LoadFile(uri, nullptr); dest = Song::LoadFile(uri, nullptr);
if (dest == nullptr) if (dest == nullptr)
return nullptr; return nullptr;
@ -147,7 +147,7 @@ playlist_check_translate_song(Song *song, const char *base_uri,
functions */ functions */
base_uri = nullptr; base_uri = nullptr;
if (g_path_is_absolute(uri)) { if (Path::IsAbsoluteUTF8(uri)) {
/* XXX fs_charset vs utf8? */ /* XXX fs_charset vs utf8? */
const char *suffix = map_to_relative_path(uri); const char *suffix = map_to_relative_path(uri);
assert(suffix != nullptr); assert(suffix != nullptr);

View File

@ -28,6 +28,7 @@
#include "TextFile.hxx" #include "TextFile.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "fs/Path.hxx"
#include "Log.hxx" #include "Log.hxx"
#include <glib.h> #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)) { if (g_str_has_prefix(line, SONG_BEGIN)) {
const char *uri = line + sizeof(SONG_BEGIN) - 1; 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; return;
Error error; Error error;

View File

@ -47,7 +47,7 @@ Song::LoadFile(const char *path_utf8, Directory *parent)
Song *song; Song *song;
bool ret; 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(!uri_has_scheme(path_utf8));
assert(strchr(path_utf8, '\n') == NULL); assert(strchr(path_utf8, '\n') == NULL);

View File

@ -295,7 +295,7 @@ skip_symlink(const Directory *directory, const char *utf8_name)
const char *target_str = target.c_str(); 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 /* if the symlink points to an absolute path, see if
that path is inside the music directory */ that path is inside the music directory */
const char *relative = map_to_relative_path(target_str); const char *relative = map_to_relative_path(target_str);

View File

@ -23,6 +23,10 @@
#include "check.h" #include "check.h"
#include "gcc.h" #include "gcc.h"
#ifdef WIN32
#include <glib.h>
#endif
#include <algorithm> #include <algorithm>
#include <string> #include <string>
@ -261,6 +265,33 @@ public:
#endif #endif
ch == SEPARATOR_UTF8; 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 #endif

View File

@ -26,6 +26,7 @@
#include "InputPlugin.hxx" #include "InputPlugin.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "fs/Path.hxx"
#include "Log.hxx" #include "Log.hxx"
#include <glib.h> #include <glib.h>
@ -49,7 +50,7 @@ input_archive_open(const char *pathname,
char *archive, *filename, *suffix, *pname; char *archive, *filename, *suffix, *pname;
struct input_stream *is; struct input_stream *is;
if (!g_path_is_absolute(pathname)) if (!Path::IsAbsoluteFS(pathname))
return NULL; return NULL;
pname = g_strdup(pathname); pname = g_strdup(pathname);

View File

@ -24,6 +24,7 @@
#include "InputPlugin.hxx" #include "InputPlugin.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "fs/Path.hxx"
#include "system/fd_util.h" #include "system/fd_util.h"
#include "open.h" #include "open.h"
@ -62,7 +63,7 @@ input_file_open(const char *filename,
int fd, ret; int fd, ret;
struct stat st; struct stat st;
if (!g_path_is_absolute(filename)) if (!Path::IsAbsoluteFS(filename))
return nullptr; return nullptr;
fd = open_cloexec(filename, O_RDONLY|O_BINARY, 0); fd = open_cloexec(filename, O_RDONLY|O_BINARY, 0);

View File

@ -34,6 +34,7 @@
#include "Song.hxx" #include "Song.hxx"
#include "TagFile.hxx" #include "TagFile.hxx"
#include "cue/CueParser.hxx" #include "cue/CueParser.hxx"
#include "fs/Path.hxx"
#include <glib.h> #include <glib.h>
#include <assert.h> #include <assert.h>
@ -95,7 +96,7 @@ embcue_playlist_open_uri(const char *uri,
gcc_unused Mutex &mutex, gcc_unused Mutex &mutex,
gcc_unused Cond &cond) gcc_unused Cond &cond)
{ {
if (!g_path_is_absolute(uri)) if (!Path::IsAbsoluteUTF8(uri))
/* only local files supported */ /* only local files supported */
return NULL; return NULL;