Don’t report empty files as directories; add more docs
This commit is contained in:
parent
c3549cd230
commit
5889512732
|
@ -109,6 +109,10 @@ pub fn parse_response_vec<'a, I: Iterator<Item = &'a str>, T: de::DeserializeOwn
|
||||||
/// Parse the `playlist` command, a list of key-value pairs, as a vector of filenames.
|
/// Parse the `playlist` command, a list of key-value pairs, as a vector of filenames.
|
||||||
/// The playlist index of each item is *not* included because, if needed,
|
/// The playlist index of each item is *not* included because, if needed,
|
||||||
/// it can easily be added with `.enumerate()`.
|
/// it can easily be added with `.enumerate()`.
|
||||||
|
///
|
||||||
|
/// Note: The MPD protocol documentation suggests using `playlistinfo` instead,
|
||||||
|
/// which returns a superset of this commands output,
|
||||||
|
/// but this isn’t deprecated, so if you only need the filenames, it should be all you need.
|
||||||
pub fn parse_playlist<'a, I: Iterator<Item = &'a str>>(input: I) -> MpdResult<Vec<&'a str>> {
|
pub fn parse_playlist<'a, I: Iterator<Item = &'a str>>(input: I) -> MpdResult<Vec<&'a str>> {
|
||||||
input
|
input
|
||||||
// `iter.scan((), |(), item| predicate(item))` is equivalent to map_while(predicate),
|
// `iter.scan((), |(), item| predicate(item))` is equivalent to map_while(predicate),
|
||||||
|
@ -433,7 +437,7 @@ OK";
|
||||||
File {
|
File {
|
||||||
name: "Scans".into(),
|
name: "Scans".into(),
|
||||||
last_modified: DateTime::parse_from_rfc3339("2015-01-30T14:53:03Z").unwrap(),
|
last_modified: DateTime::parse_from_rfc3339("2015-01-30T14:53:03Z").unwrap(),
|
||||||
size: 0
|
size: -1
|
||||||
},
|
},
|
||||||
File {
|
File {
|
||||||
name: "15 風ハ旅スル(スマートフォンゲーム「風パズル 黒猫と白猫の夢見た世界」テーマ曲).flac".into(),
|
name: "15 風ハ旅スル(スマートフォンゲーム「風パズル 黒猫と白猫の夢見た世界」テーマ曲).flac".into(),
|
||||||
|
|
|
@ -117,19 +117,33 @@ pub struct Status {
|
||||||
pub error: Option<String>,
|
pub error: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An object in the file system, as returned by the `listfiles` command.
|
||||||
|
/// For directories, the `size` will be `-1`, and [`is_directory`] is provided to check that.
|
||||||
|
///
|
||||||
|
/// [`is_directory`]: #method.is_directory
|
||||||
|
///
|
||||||
|
/// Properly parsing `listfiles` into a Vector of some enum with variants for file and directory
|
||||||
|
/// would make the deserialization code a lot more complicated, so I’m not interested in doing that
|
||||||
|
/// at this point in time.
|
||||||
#[derive(Deserialize, Clone, Debug, PartialEq)]
|
#[derive(Deserialize, Clone, Debug, PartialEq)]
|
||||||
pub struct File {
|
pub struct File {
|
||||||
#[serde(alias = "directory", rename = "file")]
|
#[serde(alias = "directory", rename = "file")]
|
||||||
pub name: String,
|
pub name: String,
|
||||||
#[serde(rename = "last-modified")]
|
#[serde(rename = "last-modified")]
|
||||||
pub last_modified: DateTime<FixedOffset>,
|
pub last_modified: DateTime<FixedOffset>,
|
||||||
#[serde(default)]
|
#[serde(default = "minus_one")]
|
||||||
pub size: usize,
|
pub size: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn minus_one() -> i64 {
|
||||||
|
-1
|
||||||
}
|
}
|
||||||
|
|
||||||
impl File {
|
impl File {
|
||||||
|
/// Returns true if this file is a directory.
|
||||||
|
/// Internally, this just checks if `size == -1`.
|
||||||
pub fn is_directory(&self) -> bool {
|
pub fn is_directory(&self) -> bool {
|
||||||
self.size == 0
|
self.size == -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user