aboutsummaryrefslogtreecommitdiffstats
path: root/src/command/FileCommands.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/command/FileCommands.cxx')
-rw-r--r--src/command/FileCommands.cxx45
1 files changed, 29 insertions, 16 deletions
diff --git a/src/command/FileCommands.cxx b/src/command/FileCommands.cxx
index 1b6a11cf5..7673c0a2e 100644
--- a/src/command/FileCommands.cxx
+++ b/src/command/FileCommands.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -25,6 +25,7 @@
#include "protocol/Ack.hxx"
#include "protocol/Result.hxx"
#include "client/Client.hxx"
+#include "util/ConstBuffer.hxx"
#include "util/CharUtil.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
@@ -35,7 +36,7 @@
#include "TagFile.hxx"
#include "storage/StorageInterface.hxx"
#include "fs/AllocatedPath.hxx"
-#include "fs/FileSystem.hxx"
+#include "fs/FileInfo.hxx"
#include "fs/DirectoryReader.hxx"
#include "TimePrint.hxx"
#include "ls.hxx"
@@ -46,7 +47,7 @@
gcc_pure
static bool
-SkipNameFS(const char *name_fs)
+SkipNameFS(PathTraitsFS::const_pointer name_fs)
{
return name_fs[0] == '.' &&
(name_fs[1] == 0 ||
@@ -55,9 +56,9 @@ SkipNameFS(const char *name_fs)
gcc_pure
static bool
-skip_path(const char *name_fs)
+skip_path(Path name_fs)
{
- return strchr(name_fs, '\n') != nullptr;
+ return name_fs.HasNewline();
}
#if defined(WIN32) && GCC_CHECK_VERSION(4,6)
@@ -89,7 +90,7 @@ handle_listfiles_local(Client &client, const char *path_utf8)
while (reader.ReadEntry()) {
const Path name_fs = reader.GetEntry();
- if (SkipNameFS(name_fs.c_str()) || skip_path(name_fs.c_str()))
+ if (SkipNameFS(name_fs.c_str()) || skip_path(name_fs))
continue;
std::string name_utf8 = name_fs.ToUTF8();
@@ -98,20 +99,22 @@ handle_listfiles_local(Client &client, const char *path_utf8)
const AllocatedPath full_fs =
AllocatedPath::Build(path_fs, name_fs);
- struct stat st;
- if (!StatFile(full_fs, st, false))
+ FileInfo fi;
+ if (!GetFileInfo(full_fs, fi, false))
continue;
- if (S_ISREG(st.st_mode)) {
+ if (fi.IsRegular())
client_printf(client, "file: %s\n"
"size: %" PRIu64 "\n",
name_utf8.c_str(),
- uint64_t(st.st_size));
- } else if (S_ISDIR(st.st_mode))
+ fi.GetSize());
+ else if (fi.IsDirectory())
client_printf(client, "directory: %s\n",
name_utf8.c_str());
+ else
+ continue;
- time_print(client, "Last-Modified", st.st_mtime);
+ time_print(client, "Last-Modified", fi.GetModificationTime());
}
return CommandResult::OK;
@@ -201,12 +204,22 @@ read_file_comments(Client &client, const Path path_fs)
}
-CommandResult
-handle_read_comments(Client &client, gcc_unused unsigned argc, char *argv[])
+static const char *
+translate_uri(const char *uri)
{
- assert(argc == 2);
+ if (memcmp(uri, "file:///", 8) == 0)
+ /* drop the "file://", leave only an absolute path
+ (starting with a slash) */
+ return uri + 7;
+
+ return uri;
+}
- const char *const uri = argv[1];
+CommandResult
+handle_read_comments(Client &client, ConstBuffer<const char *> args)
+{
+ assert(args.size == 1);
+ const char *const uri = translate_uri(args.front());
if (memcmp(uri, "file:///", 8) == 0) {
/* read comments from arbitrary local file */