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
68977af6
Commit
68977af6
authored
Oct 08, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
directory: eliminate CamelCase
CamelCase is ugly, rename the functions.
parent
bb8a9533
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
58 additions
and
58 deletions
+58
-58
database.c
src/database.c
+9
-10
dbUtils.c
src/dbUtils.c
+2
-2
directory.c
src/directory.c
+23
-23
directory.h
src/directory.h
+13
-12
dirvec.c
src/dirvec.c
+1
-1
song.c
src/song.c
+2
-2
song_print.c
src/song_print.c
+1
-1
song_save.c
src/song_save.c
+1
-1
update.c
src/update.c
+6
-6
No files found.
src/database.c
View file @
68977af6
...
...
@@ -39,7 +39,7 @@ static time_t directory_dbModTime;
void
db_init
(
void
)
{
music_root
=
newDirectory
(
NULL
,
NULL
);
music_root
=
directory_new
(
NULL
,
NULL
);
updateDirectory
(
music_root
);
stats
.
numberOfSongs
=
countSongsIn
(
NULL
);
stats
.
dbPlayTime
=
sumSongTimesIn
(
NULL
);
...
...
@@ -48,7 +48,7 @@ db_init(void)
void
db_finish
(
void
)
{
freeDirectory
(
music_root
);
directory_free
(
music_root
);
}
struct
directory
*
...
...
@@ -65,7 +65,7 @@ db_get_directory(const char *name)
if
(
name
==
NULL
)
return
music_root
;
return
getSubD
irectory
(
music_root
,
name
);
return
directory_get_d
irectory
(
music_root
,
name
);
}
struct
song
*
...
...
@@ -113,8 +113,7 @@ db_walk(const char *name,
return
-
1
;
}
return
traverseAllInSubDirectory
(
directory
,
forEachSong
,
forEachDir
,
data
);
return
directory_walk
(
directory
,
forEachSong
,
forEachDir
,
data
);
}
static
char
*
...
...
@@ -197,11 +196,11 @@ db_save(void)
struct
stat
st
;
DEBUG
(
"removing empty directories from DB
\n
"
);
d
eleteEmptyDirectoriesInDirector
y
(
music_root
);
d
irectory_prune_empt
y
(
music_root
);
DEBUG
(
"sorting DB
\n
"
);
sortDirectory
(
music_root
);
directory_sort
(
music_root
);
DEBUG
(
"writing DB
\n
"
);
...
...
@@ -218,7 +217,7 @@ db_save(void)
fprintf
(
fp
,
"%s%s
\n
"
,
DIRECTORY_FS_CHARSET
,
getFsCharset
());
fprintf
(
fp
,
"%s
\n
"
,
DIRECTORY_INFO_END
);
if
(
writeDirectoryInfo
(
fp
,
music_root
)
<
0
)
{
if
(
directory_save
(
fp
,
music_root
)
<
0
)
{
ERROR
(
"Failed to write to database file: %s
\n
"
,
strerror
(
errno
));
while
(
fclose
(
fp
)
&&
errno
==
EINTR
);
...
...
@@ -241,7 +240,7 @@ db_load(void)
struct
stat
st
;
if
(
!
music_root
)
music_root
=
newDirectory
(
NULL
,
NULL
);
music_root
=
directory_new
(
NULL
,
NULL
);
while
(
!
(
fp
=
fopen
(
dbFile
,
"r"
))
&&
errno
==
EINTR
)
;
if
(
fp
==
NULL
)
{
ERROR
(
"unable to open db file
\"
%s
\"
: %s
\n
"
,
...
...
@@ -302,7 +301,7 @@ db_load(void)
DEBUG
(
"reading DB
\n
"
);
readDirectoryInfo
(
fp
,
music_root
);
directory_load
(
fp
,
music_root
);
while
(
fclose
(
fp
)
&&
errno
==
EINTR
)
;
stats
.
numberOfSongs
=
countSongsIn
(
NULL
);
...
...
src/dbUtils.c
View file @
68977af6
...
...
@@ -62,7 +62,7 @@ printDirectoryInDirectory(struct directory *directory, void *data)
{
struct
client
*
client
=
data
;
if
(
directory
->
path
)
{
client_printf
(
client
,
"directory: %s
\n
"
,
getDirectoryP
ath
(
directory
));
client_printf
(
client
,
"directory: %s
\n
"
,
directory_get_p
ath
(
directory
));
}
return
0
;
}
...
...
@@ -374,7 +374,7 @@ sumSavedFilenameMemoryInDirectory(struct directory *dir, void *data)
if
(
!
dir
->
path
)
return
0
;
*
sum
+=
(
strlen
(
getDirectoryP
ath
(
dir
))
+
1
*
sum
+=
(
strlen
(
directory_get_p
ath
(
dir
))
+
1
-
sizeof
(
struct
directory
*
))
*
dir
->
songs
.
nr
;
return
0
;
...
...
src/directory.c
View file @
68977af6
...
...
@@ -28,7 +28,7 @@
#include "dirvec.h"
struct
directory
*
newDirectory
(
const
char
*
dirname
,
struct
directory
*
parent
)
directory_new
(
const
char
*
dirname
,
struct
directory
*
parent
)
{
struct
directory
*
directory
;
...
...
@@ -42,7 +42,7 @@ newDirectory(const char *dirname, struct directory * parent)
}
void
freeDirectory
(
struct
directory
*
directory
)
directory_free
(
struct
directory
*
directory
)
{
dirvec_destroy
(
&
directory
->
children
);
songvec_destroy
(
&
directory
->
songs
);
...
...
@@ -50,17 +50,17 @@ freeDirectory(struct directory * directory)
free
(
directory
->
path
);
free
(
directory
);
/* this resets last dir returned */
/*
getDirectoryP
ath(NULL); */
/*
directory_get_p
ath(NULL); */
}
void
d
eleteEmptyDirectoriesInDirector
y
(
struct
directory
*
directory
)
d
irectory_prune_empt
y
(
struct
directory
*
directory
)
{
int
i
;
struct
dirvec
*
dv
=
&
directory
->
children
;
for
(
i
=
dv
->
nr
;
--
i
>=
0
;
)
{
d
eleteEmptyDirectoriesInDirector
y
(
dv
->
base
[
i
]);
d
irectory_prune_empt
y
(
dv
->
base
[
i
]);
if
(
directory_is_empty
(
dv
->
base
[
i
]))
dirvec_delete
(
dv
,
dv
->
base
[
i
]);
}
...
...
@@ -69,7 +69,7 @@ deleteEmptyDirectoriesInDirectory(struct directory *directory)
}
struct
directory
*
getSubDirectory
(
struct
directory
*
directory
,
const
char
*
name
)
directory_get_directory
(
struct
directory
*
directory
,
const
char
*
name
)
{
struct
directory
*
cur
=
directory
;
struct
directory
*
found
=
NULL
;
...
...
@@ -102,13 +102,13 @@ getSubDirectory(struct directory * directory, const char *name)
}
static
int
printDirectoryLis
t
(
struct
client
*
client
,
const
struct
dirvec
*
dv
)
dirvec_prin
t
(
struct
client
*
client
,
const
struct
dirvec
*
dv
)
{
size_t
i
;
for
(
i
=
0
;
i
<
dv
->
nr
;
++
i
)
{
client_printf
(
client
,
DIRECTORY_DIR
"%s
\n
"
,
getDirectoryP
ath
(
dv
->
base
[
i
]));
directory_get_p
ath
(
dv
->
base
[
i
]));
}
return
0
;
...
...
@@ -117,7 +117,7 @@ printDirectoryList(struct client *client, const struct dirvec *dv)
int
directory_print
(
struct
client
*
client
,
const
struct
directory
*
directory
)
{
printDirectoryLis
t
(
client
,
&
directory
->
children
);
dirvec_prin
t
(
client
,
&
directory
->
children
);
songvec_print
(
client
,
&
directory
->
songs
);
return
0
;
...
...
@@ -125,7 +125,7 @@ directory_print(struct client *client, const struct directory *directory)
/* TODO error checking */
int
writeDirectoryInfo
(
FILE
*
fp
,
struct
directory
*
directory
)
directory_save
(
FILE
*
fp
,
struct
directory
*
directory
)
{
struct
dirvec
*
children
=
&
directory
->
children
;
size_t
i
;
...
...
@@ -133,7 +133,7 @@ writeDirectoryInfo(FILE * fp, struct directory * directory)
if
(
directory
->
path
)
{
retv
=
fprintf
(
fp
,
"%s%s
\n
"
,
DIRECTORY_BEGIN
,
getDirectoryP
ath
(
directory
));
directory_get_p
ath
(
directory
));
if
(
retv
<
0
)
return
-
1
;
}
...
...
@@ -145,7 +145,7 @@ writeDirectoryInfo(FILE * fp, struct directory * directory)
retv
=
fprintf
(
fp
,
DIRECTORY_DIR
"%s
\n
"
,
base
);
if
(
retv
<
0
)
return
-
1
;
if
(
writeDirectoryInfo
(
fp
,
cur
)
<
0
)
if
(
directory_save
(
fp
,
cur
)
<
0
)
return
-
1
;
}
...
...
@@ -153,13 +153,13 @@ writeDirectoryInfo(FILE * fp, struct directory * directory)
if
(
directory
->
path
&&
fprintf
(
fp
,
DIRECTORY_END
"%s
\n
"
,
getDirectoryP
ath
(
directory
))
<
0
)
directory_get_p
ath
(
directory
))
<
0
)
return
-
1
;
return
0
;
}
void
readDirectoryInfo
(
FILE
*
fp
,
struct
directory
*
directory
)
directory_load
(
FILE
*
fp
,
struct
directory
*
directory
)
{
char
buffer
[
MPD_PATH_MAX
*
2
];
int
bufferSize
=
MPD_PATH_MAX
*
2
;
...
...
@@ -185,10 +185,10 @@ readDirectoryInfo(FILE * fp, struct directory * directory)
if
((
subdir
=
db_get_directory
(
name
)))
{
assert
(
subdir
->
parent
==
directory
);
}
else
{
subdir
=
newDirectory
(
name
,
directory
);
subdir
=
directory_new
(
name
,
directory
);
dirvec_add
(
&
directory
->
children
,
subdir
);
}
readDirectoryInfo
(
fp
,
subdir
);
directory_load
(
fp
,
subdir
);
}
else
if
(
!
prefixcmp
(
buffer
,
SONG_BEGIN
))
{
readSongInfoIntoList
(
fp
,
&
directory
->
songs
,
directory
);
}
else
{
...
...
@@ -198,7 +198,7 @@ readDirectoryInfo(FILE * fp, struct directory * directory)
}
void
sortDirectory
(
struct
directory
*
directory
)
directory_sort
(
struct
directory
*
directory
)
{
int
i
;
struct
dirvec
*
dv
=
&
directory
->
children
;
...
...
@@ -207,14 +207,14 @@ sortDirectory(struct directory * directory)
songvec_sort
(
&
directory
->
songs
);
for
(
i
=
dv
->
nr
;
--
i
>=
0
;
)
sortDirectory
(
dv
->
base
[
i
]);
directory_sort
(
dv
->
base
[
i
]);
}
int
traverseAllInSubDirectory
(
struct
directory
*
directory
,
int
(
*
forEachSong
)
(
struct
song
*
,
void
*
),
int
(
*
forEachDir
)
(
struct
directory
*
,
void
*
),
void
*
data
)
directory_walk
(
struct
directory
*
directory
,
int
(
*
forEachSong
)
(
struct
song
*
,
void
*
),
int
(
*
forEachDir
)
(
struct
directory
*
,
void
*
),
void
*
data
)
{
struct
dirvec
*
dv
=
&
directory
->
children
;
int
err
=
0
;
...
...
@@ -230,7 +230,7 @@ traverseAllInSubDirectory(struct directory * directory,
}
for
(
j
=
0
;
err
>=
0
&&
j
<
dv
->
nr
;
++
j
)
err
=
traverseAllInSubDirectory
(
dv
->
base
[
j
],
forEachSong
,
err
=
directory_walk
(
dv
->
base
[
j
],
forEachSong
,
forEachDir
,
data
);
return
err
;
...
...
src/directory.h
View file @
68977af6
...
...
@@ -59,10 +59,10 @@ isRootDirectory(const char *name)
}
struct
directory
*
newDirectory
(
const
char
*
dirname
,
struct
directory
*
parent
);
directory_new
(
const
char
*
dirname
,
struct
directory
*
parent
);
void
freeDirectory
(
struct
directory
*
directory
);
directory_free
(
struct
directory
*
directory
);
static
inline
bool
directory_is_empty
(
struct
directory
*
directory
)
...
...
@@ -71,28 +71,29 @@ directory_is_empty(struct directory *directory)
}
void
d
eleteEmptyDirectoriesInDirector
y
(
struct
directory
*
directory
);
d
irectory_prune_empt
y
(
struct
directory
*
directory
);
struct
directory
*
getSubD
irectory
(
struct
directory
*
directory
,
const
char
*
name
);
directory_get_d
irectory
(
struct
directory
*
directory
,
const
char
*
name
);
int
directory_print
(
struct
client
*
client
,
const
struct
directory
*
directory
);
int
writeDirectoryInfo
(
FILE
*
fp
,
struct
directory
*
directory
);
directory_save
(
FILE
*
fp
,
struct
directory
*
directory
);
void
readDirectoryInfo
(
FILE
*
fp
,
struct
directory
*
directory
);
directory_load
(
FILE
*
fp
,
struct
directory
*
directory
);
void
sortDirectory
(
struct
directory
*
directory
);
directory_sort
(
struct
directory
*
directory
);
int
traverseAllInSubDirectory
(
struct
directory
*
directory
,
int
(
*
forEachSong
)
(
struct
song
*
,
void
*
),
int
(
*
forEachDir
)
(
struct
directory
*
,
void
*
),
void
*
data
);
directory_walk
(
struct
directory
*
directory
,
int
(
*
forEachSong
)
(
struct
song
*
,
void
*
),
int
(
*
forEachDir
)
(
struct
directory
*
,
void
*
),
void
*
data
);
#define
getDirectoryP
ath(dir) ((dir && dir->path) ? dir->path : "")
#define
directory_get_p
ath(dir) ((dir && dir->path) ? dir->path : "")
#endif
src/dirvec.c
View file @
68977af6
...
...
@@ -39,7 +39,7 @@ int dirvec_delete(struct dirvec *dv, struct directory *del)
for
(
i
=
dv
->
nr
;
--
i
>=
0
;
)
{
if
(
dv
->
base
[
i
]
!=
del
)
continue
;
/* we _don't_ call
freeDirectory
() here */
/* we _don't_ call
directory_free
() here */
if
(
!--
dv
->
nr
)
{
free
(
dv
->
base
);
dv
->
base
=
NULL
;
...
...
src/song.c
View file @
68977af6
...
...
@@ -128,7 +128,7 @@ song_get_url(struct song *song, char *path_max_tmp)
strcpy
(
path_max_tmp
,
song
->
url
);
else
pfx_dir
(
path_max_tmp
,
song
->
url
,
strlen
(
song
->
url
),
getDirectoryP
ath
(
song
->
parent
),
strlen
(
getDirectoryP
ath
(
song
->
parent
)));
directory_get_p
ath
(
song
->
parent
),
strlen
(
directory_get_p
ath
(
song
->
parent
)));
return
path_max_tmp
;
}
src/song_print.c
View file @
68977af6
...
...
@@ -28,7 +28,7 @@ song_print_url(struct client *client, struct song *song)
{
if
(
song
->
parent
&&
song
->
parent
->
path
)
{
client_printf
(
client
,
"%s%s/%s
\n
"
,
SONG_FILE
,
getDirectoryP
ath
(
song
->
parent
),
song
->
url
);
directory_get_p
ath
(
song
->
parent
),
song
->
url
);
}
else
{
client_printf
(
client
,
"%s%s
\n
"
,
SONG_FILE
,
song
->
url
);
}
...
...
src/song_save.c
View file @
68977af6
...
...
@@ -33,7 +33,7 @@ song_save_url(FILE *fp, struct song *song)
{
if
(
song
->
parent
!=
NULL
&&
song
->
parent
->
path
!=
NULL
)
fprintf
(
fp
,
SONG_FILE
"%s/%s
\n
"
,
getDirectoryP
ath
(
song
->
parent
),
song
->
url
);
directory_get_p
ath
(
song
->
parent
),
song
->
url
);
else
fprintf
(
fp
,
SONG_FILE
"%s
\n
"
,
song
->
url
);
...
...
src/update.c
View file @
68977af6
...
...
@@ -141,7 +141,7 @@ statDirectory(struct directory *dir)
{
struct
stat
st
;
if
(
myStat
(
getDirectoryP
ath
(
dir
),
&
st
)
<
0
)
if
(
myStat
(
directory_get_p
ath
(
dir
),
&
st
)
<
0
)
return
-
1
;
directory_set_stat
(
dir
,
&
st
);
...
...
@@ -174,11 +174,11 @@ addSubDirectoryToDirectory(struct directory *directory,
if
(
inodeFoundInParent
(
directory
,
st
->
st_ino
,
st
->
st_dev
))
return
UPDATE_RETURN_NOUPDATE
;
subDirectory
=
newDirectory
(
name
,
directory
);
subDirectory
=
directory_new
(
name
,
directory
);
directory_set_stat
(
subDirectory
,
st
);
if
(
updateDirectory
(
subDirectory
)
!=
UPDATE_RETURN_UPDATED
)
{
freeDirectory
(
subDirectory
);
directory_free
(
subDirectory
);
return
UPDATE_RETURN_NOUPDATE
;
}
...
...
@@ -262,7 +262,7 @@ updateDirectory(struct directory *directory)
{
bool
was_empty
=
directory_is_empty
(
directory
);
DIR
*
dir
;
const
char
*
dirname
=
getDirectoryP
ath
(
directory
);
const
char
*
dirname
=
directory_get_p
ath
(
directory
);
struct
dirent
*
ent
;
char
path_max_tmp
[
MPD_PATH_MAX
];
enum
update_return
ret
=
UPDATE_RETURN_NOUPDATE
;
...
...
@@ -336,7 +336,7 @@ addDirectoryPathToDB(const char *utf8path)
inodeFoundInParent
(
parentDirectory
,
st
.
st_ino
,
st
.
st_dev
))
return
NULL
;
else
{
directory
=
newDirectory
(
utf8path
,
parentDirectory
);
directory
=
directory_new
(
utf8path
,
parentDirectory
);
dirvec_add
(
&
parentDirectory
->
children
,
directory
);
}
}
...
...
@@ -392,7 +392,7 @@ static enum update_return updatePath(const char *utf8path)
ret
=
updateDirectory
(
directory
);
if
(
ret
!=
UPDATE_RETURN_ERROR
)
{
free
(
path
);
sortDirectory
(
directory
);
directory_sort
(
directory
);
return
ret
;
}
/* we don't want to delete the root directory */
...
...
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