Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
25f67da5
Commit
25f67da5
authored
Oct 08, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
directory: converted typedef Directory to struct directory
The struct can be forward-declared by other headers, which relaxes the header dependencies.
parent
3c1142cb
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
99 additions
and
84 deletions
+99
-84
dbUtils.c
src/dbUtils.c
+8
-6
directory.c
src/directory.c
+30
-25
directory.h
src/directory.h
+12
-12
dirvec.c
src/dirvec.c
+9
-8
dirvec.h
src/dirvec.h
+4
-4
song.c
src/song.c
+2
-2
song.h
src/song.h
+3
-3
song_save.c
src/song_save.c
+1
-1
song_save.h
src/song_save.h
+1
-1
update.c
src/update.c
+27
-20
update.h
src/update.h
+2
-2
No files found.
src/dbUtils.c
View file @
25f67da5
...
@@ -46,8 +46,8 @@ typedef struct _SearchStats {
...
@@ -46,8 +46,8 @@ typedef struct _SearchStats {
unsigned
long
playTime
;
unsigned
long
playTime
;
}
SearchStats
;
}
SearchStats
;
static
int
countSongsInDirectory
(
Directory
*
directory
,
static
int
void
*
data
)
countSongsInDirectory
(
struct
directory
*
directory
,
void
*
data
)
{
{
int
*
count
=
(
int
*
)
data
;
int
*
count
=
(
int
*
)
data
;
...
@@ -56,7 +56,8 @@ static int countSongsInDirectory(Directory * directory,
...
@@ -56,7 +56,8 @@ static int countSongsInDirectory(Directory * directory,
return
0
;
return
0
;
}
}
static
int
printDirectoryInDirectory
(
Directory
*
directory
,
void
*
data
)
static
int
printDirectoryInDirectory
(
struct
directory
*
directory
,
void
*
data
)
{
{
struct
client
*
client
=
data
;
struct
client
*
client
=
data
;
if
(
directory
->
path
)
{
if
(
directory
->
path
)
{
...
@@ -356,15 +357,16 @@ int listAllUniqueTags(struct client *client, int type, int numConditionals,
...
@@ -356,15 +357,16 @@ int listAllUniqueTags(struct client *client, int type, int numConditionals,
return
ret
;
return
ret
;
}
}
static
int
sumSavedFilenameMemoryInDirectory
(
Directory
*
dir
,
void
*
data
)
static
int
sumSavedFilenameMemoryInDirectory
(
struct
directory
*
dir
,
void
*
data
)
{
{
int
*
sum
=
data
;
int
*
sum
=
data
;
if
(
!
dir
->
path
)
if
(
!
dir
->
path
)
return
0
;
return
0
;
*
sum
+=
(
strlen
(
getDirectoryPath
(
dir
))
+
1
-
sizeof
(
Directory
*
))
*
*
sum
+=
(
strlen
(
getDirectoryPath
(
dir
))
+
1
dir
->
songs
.
nr
;
-
sizeof
(
struct
directory
*
))
*
dir
->
songs
.
nr
;
return
0
;
return
0
;
}
}
...
...
src/directory.c
View file @
25f67da5
...
@@ -40,11 +40,11 @@
...
@@ -40,11 +40,11 @@
#define DIRECTORY_MPD_VERSION "mpd_version: "
#define DIRECTORY_MPD_VERSION "mpd_version: "
#define DIRECTORY_FS_CHARSET "fs_charset: "
#define DIRECTORY_FS_CHARSET "fs_charset: "
static
D
irectory
*
music_root
;
static
struct
d
irectory
*
music_root
;
static
time_t
directory_dbModTime
;
static
time_t
directory_dbModTime
;
static
void
deleteEmptyDirectoriesInDirectory
(
D
irectory
*
directory
);
static
void
deleteEmptyDirectoriesInDirectory
(
struct
d
irectory
*
directory
);
static
char
*
getDbFile
(
void
)
static
char
*
getDbFile
(
void
)
{
{
...
@@ -56,12 +56,12 @@ static char *getDbFile(void)
...
@@ -56,12 +56,12 @@ static char *getDbFile(void)
return
param
->
value
;
return
param
->
value
;
}
}
D
irectory
*
struct
d
irectory
*
newDirectory
(
const
char
*
dirname
,
D
irectory
*
parent
)
newDirectory
(
const
char
*
dirname
,
struct
d
irectory
*
parent
)
{
{
D
irectory
*
directory
;
struct
d
irectory
*
directory
;
directory
=
xcalloc
(
1
,
sizeof
(
D
irectory
));
directory
=
xcalloc
(
1
,
sizeof
(
*
d
irectory
));
if
(
dirname
&&
strlen
(
dirname
))
if
(
dirname
&&
strlen
(
dirname
))
directory
->
path
=
xstrdup
(
dirname
);
directory
->
path
=
xstrdup
(
dirname
);
...
@@ -71,7 +71,7 @@ newDirectory(const char *dirname, Directory * parent)
...
@@ -71,7 +71,7 @@ newDirectory(const char *dirname, Directory * parent)
}
}
void
void
freeDirectory
(
D
irectory
*
directory
)
freeDirectory
(
struct
d
irectory
*
directory
)
{
{
dirvec_destroy
(
&
directory
->
children
);
dirvec_destroy
(
&
directory
->
children
);
songvec_destroy
(
&
directory
->
songs
);
songvec_destroy
(
&
directory
->
songs
);
...
@@ -82,7 +82,7 @@ freeDirectory(Directory * directory)
...
@@ -82,7 +82,7 @@ freeDirectory(Directory * directory)
/*getDirectoryPath(NULL); */
/*getDirectoryPath(NULL); */
}
}
static
void
deleteEmptyDirectoriesInDirectory
(
D
irectory
*
directory
)
static
void
deleteEmptyDirectoriesInDirectory
(
struct
d
irectory
*
directory
)
{
{
int
i
;
int
i
;
struct
dirvec
*
dv
=
&
directory
->
children
;
struct
dirvec
*
dv
=
&
directory
->
children
;
...
@@ -106,7 +106,7 @@ int isRootDirectory(const char *name)
...
@@ -106,7 +106,7 @@ int isRootDirectory(const char *name)
return
(
!
name
||
name
[
0
]
==
'\0'
||
!
strcmp
(
name
,
"/"
));
return
(
!
name
||
name
[
0
]
==
'\0'
||
!
strcmp
(
name
,
"/"
));
}
}
D
irectory
*
struct
d
irectory
*
directory_get_root
(
void
)
directory_get_root
(
void
)
{
{
assert
(
music_root
!=
NULL
);
assert
(
music_root
!=
NULL
);
...
@@ -114,10 +114,11 @@ directory_get_root(void)
...
@@ -114,10 +114,11 @@ directory_get_root(void)
return
music_root
;
return
music_root
;
}
}
static
Directory
*
getSubDirectory
(
Directory
*
directory
,
const
char
*
name
)
static
struct
directory
*
getSubDirectory
(
struct
directory
*
directory
,
const
char
*
name
)
{
{
D
irectory
*
cur
=
directory
;
struct
d
irectory
*
cur
=
directory
;
D
irectory
*
found
=
NULL
;
struct
d
irectory
*
found
=
NULL
;
char
*
duplicated
;
char
*
duplicated
;
char
*
locate
;
char
*
locate
;
...
@@ -144,7 +145,7 @@ static Directory *getSubDirectory(Directory * directory, const char *name)
...
@@ -144,7 +145,7 @@ static Directory *getSubDirectory(Directory * directory, const char *name)
return
found
;
return
found
;
}
}
D
irectory
*
struct
d
irectory
*
getDirectory
(
const
char
*
name
)
getDirectory
(
const
char
*
name
)
{
{
return
getSubDirectory
(
music_root
,
name
);
return
getSubDirectory
(
music_root
,
name
);
...
@@ -164,7 +165,7 @@ static int printDirectoryList(struct client *client, struct dirvec *dv)
...
@@ -164,7 +165,7 @@ static int printDirectoryList(struct client *client, struct dirvec *dv)
int
printDirectoryInfo
(
struct
client
*
client
,
const
char
*
name
)
int
printDirectoryInfo
(
struct
client
*
client
,
const
char
*
name
)
{
{
D
irectory
*
directory
;
struct
d
irectory
*
directory
;
if
((
directory
=
getDirectory
(
name
))
==
NULL
)
if
((
directory
=
getDirectory
(
name
))
==
NULL
)
return
-
1
;
return
-
1
;
...
@@ -176,7 +177,8 @@ int printDirectoryInfo(struct client *client, const char *name)
...
@@ -176,7 +177,8 @@ int printDirectoryInfo(struct client *client, const char *name)
}
}
/* TODO error checking */
/* TODO error checking */
static
int
writeDirectoryInfo
(
FILE
*
fp
,
Directory
*
directory
)
static
int
writeDirectoryInfo
(
FILE
*
fp
,
struct
directory
*
directory
)
{
{
struct
dirvec
*
children
=
&
directory
->
children
;
struct
dirvec
*
children
=
&
directory
->
children
;
size_t
i
;
size_t
i
;
...
@@ -190,7 +192,7 @@ static int writeDirectoryInfo(FILE * fp, Directory * directory)
...
@@ -190,7 +192,7 @@ static int writeDirectoryInfo(FILE * fp, Directory * directory)
}
}
for
(
i
=
0
;
i
<
children
->
nr
;
++
i
)
{
for
(
i
=
0
;
i
<
children
->
nr
;
++
i
)
{
D
irectory
*
cur
=
children
->
base
[
i
];
struct
d
irectory
*
cur
=
children
->
base
[
i
];
const
char
*
base
=
mpd_basename
(
cur
->
path
);
const
char
*
base
=
mpd_basename
(
cur
->
path
);
retv
=
fprintf
(
fp
,
DIRECTORY_DIR
"%s
\n
"
,
base
);
retv
=
fprintf
(
fp
,
DIRECTORY_DIR
"%s
\n
"
,
base
);
...
@@ -209,7 +211,8 @@ static int writeDirectoryInfo(FILE * fp, Directory * directory)
...
@@ -209,7 +211,8 @@ static int writeDirectoryInfo(FILE * fp, Directory * directory)
return
0
;
return
0
;
}
}
static
void
readDirectoryInfo
(
FILE
*
fp
,
Directory
*
directory
)
static
void
readDirectoryInfo
(
FILE
*
fp
,
struct
directory
*
directory
)
{
{
char
buffer
[
MPD_PATH_MAX
*
2
];
char
buffer
[
MPD_PATH_MAX
*
2
];
int
bufferSize
=
MPD_PATH_MAX
*
2
;
int
bufferSize
=
MPD_PATH_MAX
*
2
;
...
@@ -219,7 +222,7 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
...
@@ -219,7 +222,7 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
while
(
myFgets
(
buffer
,
bufferSize
,
fp
)
while
(
myFgets
(
buffer
,
bufferSize
,
fp
)
&&
prefixcmp
(
buffer
,
DIRECTORY_END
))
{
&&
prefixcmp
(
buffer
,
DIRECTORY_END
))
{
if
(
!
prefixcmp
(
buffer
,
DIRECTORY_DIR
))
{
if
(
!
prefixcmp
(
buffer
,
DIRECTORY_DIR
))
{
D
irectory
*
subdir
;
struct
d
irectory
*
subdir
;
strcpy
(
key
,
&
(
buffer
[
strlen
(
DIRECTORY_DIR
)]));
strcpy
(
key
,
&
(
buffer
[
strlen
(
DIRECTORY_DIR
)]));
if
(
!
myFgets
(
buffer
,
bufferSize
,
fp
))
if
(
!
myFgets
(
buffer
,
bufferSize
,
fp
))
...
@@ -248,7 +251,7 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
...
@@ -248,7 +251,7 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
}
}
void
void
sortDirectory
(
D
irectory
*
directory
)
sortDirectory
(
struct
d
irectory
*
directory
)
{
{
int
i
;
int
i
;
struct
dirvec
*
dv
=
&
directory
->
children
;
struct
dirvec
*
dv
=
&
directory
->
children
;
...
@@ -443,9 +446,10 @@ int readDirectoryDB(void)
...
@@ -443,9 +446,10 @@ int readDirectoryDB(void)
return
0
;
return
0
;
}
}
static
int
traverseAllInSubDirectory
(
Directory
*
directory
,
static
int
traverseAllInSubDirectory
(
struct
directory
*
directory
,
int
(
*
forEachSong
)
(
Song
*
,
void
*
),
int
(
*
forEachSong
)
(
Song
*
,
void
*
),
int
(
*
forEachDir
)
(
D
irectory
*
,
void
*
),
int
(
*
forEachDir
)
(
struct
d
irectory
*
,
void
*
),
void
*
data
)
void
*
data
)
{
{
struct
dirvec
*
dv
=
&
directory
->
children
;
struct
dirvec
*
dv
=
&
directory
->
children
;
...
@@ -468,11 +472,12 @@ static int traverseAllInSubDirectory(Directory * directory,
...
@@ -468,11 +472,12 @@ static int traverseAllInSubDirectory(Directory * directory,
return
err
;
return
err
;
}
}
int
traverseAllIn
(
const
char
*
name
,
int
traverseAllIn
(
const
char
*
name
,
int
(
*
forEachSong
)
(
Song
*
,
void
*
),
int
(
*
forEachSong
)
(
Song
*
,
void
*
),
int
(
*
forEachDir
)
(
D
irectory
*
,
void
*
),
void
*
data
)
int
(
*
forEachDir
)
(
struct
d
irectory
*
,
void
*
),
void
*
data
)
{
{
D
irectory
*
directory
;
struct
d
irectory
*
directory
;
if
((
directory
=
getDirectory
(
name
))
==
NULL
)
{
if
((
directory
=
getDirectory
(
name
))
==
NULL
)
{
Song
*
song
;
Song
*
song
;
...
@@ -497,7 +502,7 @@ void directory_init(void)
...
@@ -497,7 +502,7 @@ void directory_init(void)
Song
*
getSongFromDB
(
const
char
*
file
)
Song
*
getSongFromDB
(
const
char
*
file
)
{
{
Song
*
song
=
NULL
;
Song
*
song
=
NULL
;
D
irectory
*
directory
;
struct
d
irectory
*
directory
;
char
*
dir
=
NULL
;
char
*
dir
=
NULL
;
char
*
duplicated
=
xstrdup
(
file
);
char
*
duplicated
=
xstrdup
(
file
);
char
*
shortname
=
strrchr
(
duplicated
,
'/'
);
char
*
shortname
=
strrchr
(
duplicated
,
'/'
);
...
...
src/directory.h
View file @
25f67da5
...
@@ -26,19 +26,19 @@
...
@@ -26,19 +26,19 @@
#include <stdbool.h>
#include <stdbool.h>
struct
dirvec
{
struct
dirvec
{
struct
_D
irectory
**
base
;
struct
d
irectory
**
base
;
size_t
nr
;
size_t
nr
;
};
};
typedef
struct
_D
irectory
{
struct
d
irectory
{
char
*
path
;
char
*
path
;
struct
dirvec
children
;
struct
dirvec
children
;
struct
songvec
songs
;
struct
songvec
songs
;
struct
_D
irectory
*
parent
;
struct
d
irectory
*
parent
;
ino_t
inode
;
ino_t
inode
;
dev_t
device
;
dev_t
device
;
unsigned
stat
;
/* not needed if ino_t == dev_t == 0 is impossible */
unsigned
stat
;
/* not needed if ino_t == dev_t == 0 is impossible */
}
Directory
;
};
void
directory_init
(
void
);
void
directory_init
(
void
);
...
@@ -46,26 +46,26 @@ void directory_finish(void);
...
@@ -46,26 +46,26 @@ void directory_finish(void);
int
isRootDirectory
(
const
char
*
name
);
int
isRootDirectory
(
const
char
*
name
);
D
irectory
*
struct
d
irectory
*
directory_get_root
(
void
);
directory_get_root
(
void
);
D
irectory
*
struct
d
irectory
*
newDirectory
(
const
char
*
dirname
,
D
irectory
*
parent
);
newDirectory
(
const
char
*
dirname
,
struct
d
irectory
*
parent
);
void
void
freeDirectory
(
D
irectory
*
directory
);
freeDirectory
(
struct
d
irectory
*
directory
);
static
inline
bool
static
inline
bool
directory_is_empty
(
D
irectory
*
directory
)
directory_is_empty
(
struct
d
irectory
*
directory
)
{
{
return
directory
->
children
.
nr
==
0
&&
directory
->
songs
.
nr
==
0
;
return
directory
->
children
.
nr
==
0
&&
directory
->
songs
.
nr
==
0
;
}
}
D
irectory
*
struct
d
irectory
*
getDirectory
(
const
char
*
name
);
getDirectory
(
const
char
*
name
);
void
void
sortDirectory
(
D
irectory
*
directory
);
sortDirectory
(
struct
d
irectory
*
directory
);
int
printDirectoryInfo
(
struct
client
*
client
,
const
char
*
dirname
);
int
printDirectoryInfo
(
struct
client
*
client
,
const
char
*
dirname
);
...
@@ -81,7 +81,7 @@ time_t getDbModTime(void);
...
@@ -81,7 +81,7 @@ time_t getDbModTime(void);
int
traverseAllIn
(
const
char
*
name
,
int
traverseAllIn
(
const
char
*
name
,
int
(
*
forEachSong
)
(
Song
*
,
void
*
),
int
(
*
forEachSong
)
(
Song
*
,
void
*
),
int
(
*
forEachDir
)
(
D
irectory
*
,
void
*
),
void
*
data
);
int
(
*
forEachDir
)
(
struct
d
irectory
*
,
void
*
),
void
*
data
);
#define getDirectoryPath(dir) ((dir && dir->path) ? dir->path : "")
#define getDirectoryPath(dir) ((dir && dir->path) ? dir->path : "")
...
...
src/dirvec.c
View file @
25f67da5
#include "dirvec.h"
#include "dirvec.h"
#include "directory.h"
#include "os_compat.h"
#include "os_compat.h"
#include "utils.h"
#include "utils.h"
static
size_t
dv_size
(
struct
dirvec
*
dv
)
static
size_t
dv_size
(
struct
dirvec
*
dv
)
{
{
return
dv
->
nr
*
sizeof
(
D
irectory
*
);
return
dv
->
nr
*
sizeof
(
struct
d
irectory
*
);
}
}
/* Only used for sorting/searching a dirvec, not general purpose compares */
/* Only used for sorting/searching a dirvec, not general purpose compares */
static
int
dirvec_cmp
(
const
void
*
d1
,
const
void
*
d2
)
static
int
dirvec_cmp
(
const
void
*
d1
,
const
void
*
d2
)
{
{
const
Directory
*
a
=
((
const
D
irectory
*
const
*
)
d1
)[
0
];
const
struct
directory
*
a
=
((
const
struct
d
irectory
*
const
*
)
d1
)[
0
];
const
Directory
*
b
=
((
const
D
irectory
*
const
*
)
d2
)[
0
];
const
struct
directory
*
b
=
((
const
struct
d
irectory
*
const
*
)
d2
)[
0
];
return
strcmp
(
a
->
path
,
b
->
path
);
return
strcmp
(
a
->
path
,
b
->
path
);
}
}
void
dirvec_sort
(
struct
dirvec
*
dv
)
void
dirvec_sort
(
struct
dirvec
*
dv
)
{
{
qsort
(
dv
->
base
,
dv
->
nr
,
sizeof
(
D
irectory
*
),
dirvec_cmp
);
qsort
(
dv
->
base
,
dv
->
nr
,
sizeof
(
struct
d
irectory
*
),
dirvec_cmp
);
}
}
D
irectory
*
dirvec_find
(
struct
dirvec
*
dv
,
const
char
*
path
)
struct
d
irectory
*
dirvec_find
(
struct
dirvec
*
dv
,
const
char
*
path
)
{
{
int
i
;
int
i
;
...
@@ -30,7 +31,7 @@ Directory *dirvec_find(struct dirvec *dv, const char *path)
...
@@ -30,7 +31,7 @@ Directory *dirvec_find(struct dirvec *dv, const char *path)
return
NULL
;
return
NULL
;
}
}
int
dirvec_delete
(
struct
dirvec
*
dv
,
D
irectory
*
del
)
int
dirvec_delete
(
struct
dirvec
*
dv
,
struct
d
irectory
*
del
)
{
{
int
i
;
int
i
;
...
@@ -43,7 +44,7 @@ int dirvec_delete(struct dirvec *dv, Directory *del)
...
@@ -43,7 +44,7 @@ int dirvec_delete(struct dirvec *dv, Directory *del)
dv
->
base
=
NULL
;
dv
->
base
=
NULL
;
}
else
{
}
else
{
memmove
(
&
dv
->
base
[
i
],
&
dv
->
base
[
i
+
1
],
memmove
(
&
dv
->
base
[
i
],
&
dv
->
base
[
i
+
1
],
(
dv
->
nr
-
i
+
1
)
*
sizeof
(
D
irectory
*
));
(
dv
->
nr
-
i
+
1
)
*
sizeof
(
struct
d
irectory
*
));
dv
->
base
=
xrealloc
(
dv
->
base
,
dv_size
(
dv
));
dv
->
base
=
xrealloc
(
dv
->
base
,
dv_size
(
dv
));
}
}
return
i
;
return
i
;
...
@@ -52,7 +53,7 @@ int dirvec_delete(struct dirvec *dv, Directory *del)
...
@@ -52,7 +53,7 @@ int dirvec_delete(struct dirvec *dv, Directory *del)
return
-
1
;
/* not found */
return
-
1
;
/* not found */
}
}
void
dirvec_add
(
struct
dirvec
*
dv
,
D
irectory
*
add
)
void
dirvec_add
(
struct
dirvec
*
dv
,
struct
d
irectory
*
add
)
{
{
++
dv
->
nr
;
++
dv
->
nr
;
dv
->
base
=
xrealloc
(
dv
->
base
,
dv_size
(
dv
));
dv
->
base
=
xrealloc
(
dv
->
base
,
dv_size
(
dv
));
...
...
src/dirvec.h
View file @
25f67da5
#ifndef DIRVEC_H
#ifndef DIRVEC_H
#define DIRVEC_H
#define DIRVEC_H
#include "directory.h"
struct
dirvec
;
void
dirvec_sort
(
struct
dirvec
*
dv
);
void
dirvec_sort
(
struct
dirvec
*
dv
);
D
irectory
*
dirvec_find
(
struct
dirvec
*
dv
,
const
char
*
path
);
struct
d
irectory
*
dirvec_find
(
struct
dirvec
*
dv
,
const
char
*
path
);
int
dirvec_delete
(
struct
dirvec
*
dv
,
D
irectory
*
del
);
int
dirvec_delete
(
struct
dirvec
*
dv
,
struct
d
irectory
*
del
);
void
dirvec_add
(
struct
dirvec
*
dv
,
D
irectory
*
add
);
void
dirvec_add
(
struct
dirvec
*
dv
,
struct
d
irectory
*
add
);
void
dirvec_destroy
(
struct
dirvec
*
dv
);
void
dirvec_destroy
(
struct
dirvec
*
dv
);
...
...
src/song.c
View file @
25f67da5
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
#include "os_compat.h"
#include "os_compat.h"
Song
*
Song
*
song_alloc
(
const
char
*
url
,
struct
_D
irectory
*
parent
)
song_alloc
(
const
char
*
url
,
struct
d
irectory
*
parent
)
{
{
size_t
urllen
;
size_t
urllen
;
Song
*
song
;
Song
*
song
;
...
@@ -46,7 +46,7 @@ song_alloc(const char *url, struct _Directory *parent)
...
@@ -46,7 +46,7 @@ song_alloc(const char *url, struct _Directory *parent)
return
song
;
return
song
;
}
}
Song
*
newSong
(
const
char
*
url
,
Directory
*
parentDir
)
Song
*
newSong
(
const
char
*
url
,
struct
directory
*
parentDir
)
{
{
Song
*
song
;
Song
*
song
;
assert
(
*
url
);
assert
(
*
url
);
...
...
src/song.h
View file @
25f67da5
...
@@ -32,15 +32,15 @@ struct client;
...
@@ -32,15 +32,15 @@ struct client;
typedef
struct
_Song
{
typedef
struct
_Song
{
struct
tag
*
tag
;
struct
tag
*
tag
;
struct
_D
irectory
*
parentDir
;
struct
d
irectory
*
parentDir
;
time_t
mtime
;
time_t
mtime
;
char
url
[
sizeof
(
size_t
)];
char
url
[
sizeof
(
size_t
)];
}
Song
;
}
Song
;
Song
*
Song
*
song_alloc
(
const
char
*
url
,
struct
_D
irectory
*
parent
);
song_alloc
(
const
char
*
url
,
struct
d
irectory
*
parent
);
Song
*
newSong
(
const
char
*
url
,
struct
_D
irectory
*
parentDir
);
Song
*
newSong
(
const
char
*
url
,
struct
d
irectory
*
parentDir
);
void
freeJustSong
(
Song
*
);
void
freeJustSong
(
Song
*
);
...
...
src/song_save.c
View file @
25f67da5
...
@@ -98,7 +98,7 @@ static int matchesAnMpdTagItemKey(char *buffer, int *itemType)
...
@@ -98,7 +98,7 @@ static int matchesAnMpdTagItemKey(char *buffer, int *itemType)
}
}
void
readSongInfoIntoList
(
FILE
*
fp
,
struct
songvec
*
sv
,
void
readSongInfoIntoList
(
FILE
*
fp
,
struct
songvec
*
sv
,
D
irectory
*
parentDir
)
struct
d
irectory
*
parentDir
)
{
{
char
buffer
[
MPD_PATH_MAX
+
1024
];
char
buffer
[
MPD_PATH_MAX
+
1024
];
int
bufferSize
=
MPD_PATH_MAX
+
1024
;
int
bufferSize
=
MPD_PATH_MAX
+
1024
;
...
...
src/song_save.h
View file @
25f67da5
...
@@ -26,6 +26,6 @@ struct songvec;
...
@@ -26,6 +26,6 @@ struct songvec;
void
songvec_save
(
FILE
*
fp
,
struct
songvec
*
sv
);
void
songvec_save
(
FILE
*
fp
,
struct
songvec
*
sv
);
void
readSongInfoIntoList
(
FILE
*
fp
,
struct
songvec
*
sv
,
void
readSongInfoIntoList
(
FILE
*
fp
,
struct
songvec
*
sv
,
struct
_D
irectory
*
parent
);
struct
d
irectory
*
parent
);
#endif
#endif
src/update.c
View file @
25f67da5
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
*/
*/
#include "update.h"
#include "update.h"
#include "directory.h"
#include "log.h"
#include "log.h"
#include "ls.h"
#include "ls.h"
#include "path.h"
#include "path.h"
...
@@ -53,14 +54,16 @@ int isUpdatingDB(void)
...
@@ -53,14 +54,16 @@ int isUpdatingDB(void)
return
(
progress
!=
UPDATE_PROGRESS_IDLE
)
?
update_task_id
:
0
;
return
(
progress
!=
UPDATE_PROGRESS_IDLE
)
?
update_task_id
:
0
;
}
}
static
void
directory_set_stat
(
Directory
*
dir
,
const
struct
stat
*
st
)
static
void
directory_set_stat
(
struct
directory
*
dir
,
const
struct
stat
*
st
)
{
{
dir
->
inode
=
st
->
st_ino
;
dir
->
inode
=
st
->
st_ino
;
dir
->
device
=
st
->
st_dev
;
dir
->
device
=
st
->
st_dev
;
dir
->
stat
=
1
;
dir
->
stat
=
1
;
}
}
static
void
delete_song
(
Directory
*
dir
,
Song
*
del
)
static
void
delete_song
(
struct
directory
*
dir
,
Song
*
del
)
{
{
/* first, prevent traversers in main task from getting this */
/* first, prevent traversers in main task from getting this */
songvec_delete
(
&
dir
->
songs
,
del
);
songvec_delete
(
&
dir
->
songs
,
del
);
...
@@ -79,7 +82,7 @@ static void delete_song(Directory *dir, Song *del)
...
@@ -79,7 +82,7 @@ static void delete_song(Directory *dir, Song *del)
struct
delete_data
{
struct
delete_data
{
char
*
tmp
;
char
*
tmp
;
D
irectory
*
dir
;
struct
d
irectory
*
dir
;
enum
update_return
ret
;
enum
update_return
ret
;
};
};
...
@@ -99,7 +102,7 @@ static int delete_song_if_removed(Song *song, void *_data)
...
@@ -99,7 +102,7 @@ static int delete_song_if_removed(Song *song, void *_data)
}
}
static
enum
update_return
static
enum
update_return
removeDeletedFromDirectory
(
char
*
path_max_tmp
,
Directory
*
directory
)
removeDeletedFromDirectory
(
char
*
path_max_tmp
,
struct
directory
*
directory
)
{
{
enum
update_return
ret
=
UPDATE_RETURN_NOUPDATE
;
enum
update_return
ret
=
UPDATE_RETURN_NOUPDATE
;
int
i
;
int
i
;
...
@@ -130,7 +133,8 @@ static const char *opendir_path(char *path_max_tmp, const char *dirname)
...
@@ -130,7 +133,8 @@ static const char *opendir_path(char *path_max_tmp, const char *dirname)
return
musicDir
;
return
musicDir
;
}
}
static
int
statDirectory
(
Directory
*
dir
)
static
int
statDirectory
(
struct
directory
*
dir
)
{
{
struct
stat
st
;
struct
stat
st
;
...
@@ -142,7 +146,8 @@ static int statDirectory(Directory * dir)
...
@@ -142,7 +146,8 @@ static int statDirectory(Directory * dir)
return
0
;
return
0
;
}
}
static
int
inodeFoundInParent
(
Directory
*
parent
,
ino_t
inode
,
dev_t
device
)
static
int
inodeFoundInParent
(
struct
directory
*
parent
,
ino_t
inode
,
dev_t
device
)
{
{
while
(
parent
)
{
while
(
parent
)
{
if
(
!
parent
->
stat
&&
statDirectory
(
parent
)
<
0
)
if
(
!
parent
->
stat
&&
statDirectory
(
parent
)
<
0
)
...
@@ -158,10 +163,10 @@ static int inodeFoundInParent(Directory * parent, ino_t inode, dev_t device)
...
@@ -158,10 +163,10 @@ static int inodeFoundInParent(Directory * parent, ino_t inode, dev_t device)
}
}
static
enum
update_return
static
enum
update_return
addSubDirectoryToDirectory
(
Directory
*
directory
,
addSubDirectoryToDirectory
(
struct
directory
*
directory
,
const
char
*
name
,
struct
stat
*
st
)
const
char
*
name
,
struct
stat
*
st
)
{
{
D
irectory
*
subDirectory
;
struct
d
irectory
*
subDirectory
;
if
(
inodeFoundInParent
(
directory
,
st
->
st_ino
,
st
->
st_dev
))
if
(
inodeFoundInParent
(
directory
,
st
->
st_ino
,
st
->
st_dev
))
return
UPDATE_RETURN_NOUPDATE
;
return
UPDATE_RETURN_NOUPDATE
;
...
@@ -180,7 +185,7 @@ addSubDirectoryToDirectory(Directory * directory,
...
@@ -180,7 +185,7 @@ addSubDirectoryToDirectory(Directory * directory,
}
}
static
enum
update_return
static
enum
update_return
addToDirectory
(
Directory
*
directory
,
const
char
*
name
)
addToDirectory
(
struct
directory
*
directory
,
const
char
*
name
)
{
{
struct
stat
st
;
struct
stat
st
;
...
@@ -209,7 +214,7 @@ addToDirectory(Directory * directory, const char *name)
...
@@ -209,7 +214,7 @@ addToDirectory(Directory * directory, const char *name)
}
}
static
enum
update_return
static
enum
update_return
updateInDirectory
(
Directory
*
directory
,
const
char
*
name
)
updateInDirectory
(
struct
directory
*
directory
,
const
char
*
name
)
{
{
Song
*
song
;
Song
*
song
;
struct
stat
st
;
struct
stat
st
;
...
@@ -230,7 +235,7 @@ updateInDirectory(Directory * directory, const char *name)
...
@@ -230,7 +235,7 @@ updateInDirectory(Directory * directory, const char *name)
return
UPDATE_RETURN_UPDATED
;
return
UPDATE_RETURN_UPDATED
;
}
}
}
else
if
(
S_ISDIR
(
st
.
st_mode
))
{
}
else
if
(
S_ISDIR
(
st
.
st_mode
))
{
D
irectory
*
subdir
=
dirvec_find
(
&
directory
->
children
,
name
);
struct
d
irectory
*
subdir
=
dirvec_find
(
&
directory
->
children
,
name
);
if
(
subdir
)
{
if
(
subdir
)
{
assert
(
directory
==
subdir
->
parent
);
assert
(
directory
==
subdir
->
parent
);
directory_set_stat
(
subdir
,
&
st
);
directory_set_stat
(
subdir
,
&
st
);
...
@@ -250,7 +255,7 @@ static int skip_path(const char *path)
...
@@ -250,7 +255,7 @@ static int skip_path(const char *path)
}
}
enum
update_return
enum
update_return
updateDirectory
(
Directory
*
directory
)
updateDirectory
(
struct
directory
*
directory
)
{
{
bool
was_empty
=
directory_is_empty
(
directory
);
bool
was_empty
=
directory_is_empty
(
directory
);
DIR
*
dir
;
DIR
*
dir
;
...
@@ -301,12 +306,13 @@ updateDirectory(Directory * directory)
...
@@ -301,12 +306,13 @@ updateDirectory(Directory * directory)
return
ret
;
return
ret
;
}
}
static
Directory
*
addDirectoryPathToDB
(
const
char
*
utf8path
)
static
struct
directory
*
addDirectoryPathToDB
(
const
char
*
utf8path
)
{
{
char
path_max_tmp
[
MPD_PATH_MAX
];
char
path_max_tmp
[
MPD_PATH_MAX
];
char
*
parent
;
char
*
parent
;
D
irectory
*
parentDirectory
;
struct
d
irectory
*
parentDirectory
;
D
irectory
*
directory
;
struct
d
irectory
*
directory
;
Song
*
conflicting
;
Song
*
conflicting
;
parent
=
parent_path
(
path_max_tmp
,
utf8path
);
parent
=
parent_path
(
path_max_tmp
,
utf8path
);
...
@@ -342,11 +348,12 @@ static Directory *addDirectoryPathToDB(const char *utf8path)
...
@@ -342,11 +348,12 @@ static Directory *addDirectoryPathToDB(const char *utf8path)
return
directory
;
return
directory
;
}
}
static
Directory
*
addParentPathToDB
(
const
char
*
utf8path
)
static
struct
directory
*
addParentPathToDB
(
const
char
*
utf8path
)
{
{
char
*
parent
;
char
*
parent
;
char
path_max_tmp
[
MPD_PATH_MAX
];
char
path_max_tmp
[
MPD_PATH_MAX
];
D
irectory
*
parentDirectory
;
struct
d
irectory
*
parentDirectory
;
parent
=
parent_path
(
path_max_tmp
,
utf8path
);
parent
=
parent_path
(
path_max_tmp
,
utf8path
);
...
@@ -358,13 +365,13 @@ static Directory *addParentPathToDB(const char *utf8path)
...
@@ -358,13 +365,13 @@ static Directory *addParentPathToDB(const char *utf8path)
if
(
!
parentDirectory
)
if
(
!
parentDirectory
)
return
NULL
;
return
NULL
;
return
(
D
irectory
*
)
parentDirectory
;
return
(
struct
d
irectory
*
)
parentDirectory
;
}
}
static
enum
update_return
updatePath
(
const
char
*
utf8path
)
static
enum
update_return
updatePath
(
const
char
*
utf8path
)
{
{
D
irectory
*
directory
;
struct
d
irectory
*
directory
;
D
irectory
*
parentDirectory
;
struct
d
irectory
*
parentDirectory
;
Song
*
song
;
Song
*
song
;
char
*
path
=
sanitizePathDup
(
utf8path
);
char
*
path
=
sanitizePathDup
(
utf8path
);
time_t
mtime
;
time_t
mtime
;
...
...
src/update.h
View file @
25f67da5
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
#ifndef UPDATE_H
#ifndef UPDATE_H
#define UPDATE_H
#define UPDATE_H
#include "directory.h"
struct
directory
;
enum
update_return
{
enum
update_return
{
UPDATE_RETURN_ERROR
=
-
1
,
UPDATE_RETURN_ERROR
=
-
1
,
...
@@ -31,7 +31,7 @@ enum update_return {
...
@@ -31,7 +31,7 @@ enum update_return {
int
isUpdatingDB
(
void
);
int
isUpdatingDB
(
void
);
enum
update_return
enum
update_return
updateDirectory
(
Directory
*
directory
);
updateDirectory
(
struct
directory
*
directory
);
/*
/*
* returns the non-negative update job ID on success,
* returns the non-negative update job ID on success,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment