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
2a24a94b
Commit
2a24a94b
authored
Apr 14, 2004
by
Warren Dukes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ok, finished incremental update!
now just need to polish up a few things with update git-svn-id:
https://svn.musicpd.org/mpd/trunk@745
09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent
ba1d3302
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
135 additions
and
28 deletions
+135
-28
TODO
TODO
+0
-3
directory.c
src/directory.c
+93
-25
path.c
src/path.c
+39
-0
path.h
src/path.h
+3
-0
No files found.
TODO
View file @
2a24a94b
...
...
@@ -4,9 +4,6 @@
quit in the middle of an update
k) when bg-update, have parent print out new old stuff to log on
reading db, not the child
m) MOST IMPORTANT: update needs to deal better with directories/files
that don't exist in the db, but do exit in the fs (i.e.
calling updated on a newly created file).
n) mpd command for rereading db
o) rewrite update functions to indicate if something was updated, then
when update process returns, indicate wheater db was updated
...
...
src/directory.c
View file @
2a24a94b
...
...
@@ -94,7 +94,7 @@ void deleteEmptyDirectoriesInDirectory(Directory * directory);
void
removeSongFromDirectory
(
Directory
*
directory
,
char
*
shortname
);
int
addSubDirectoryToDirectory
(
Directory
*
directory
,
char
*
shortname
,
Directory
*
addSubDirectoryToDirectory
(
Directory
*
directory
,
char
*
shortname
,
char
*
name
);
Directory
*
getDirectoryDetails
(
char
*
name
,
char
**
shortname
,
...
...
@@ -107,6 +107,8 @@ Song * getSongDetails(char * file, char ** shortnameRet,
void
updatePath
(
char
*
utf8path
);
void
sortDirectory
(
Directory
*
directory
);
void
clearUpdatePid
()
{
directory_updatePid
=
0
;
}
...
...
@@ -312,15 +314,12 @@ int removeDeletedFromDirectory(Directory * directory) {
if
(
!
utf8
)
continue
;
utf8
=
strdup
(
utf8
);
if
(
directory
->
utf8name
)
{
s
=
malloc
(
strlen
(
directory
->
utf8name
)
+
strlen
(
utf8
)
+
2
);
sprintf
(
s
,
"%s/%s"
,
directory
->
utf8name
,
utf8
);
}
else
s
=
strdup
(
utf8
);
insertInList
(
entList
,
utf8
,
s
);
free
(
utf8
);
}
closedir
(
dir
);
...
...
@@ -331,11 +330,14 @@ int removeDeletedFromDirectory(Directory * directory) {
if
(
findInList
(
entList
,
node
->
key
,
&
name
))
{
if
(
!
isDir
((
char
*
)
name
,
NULL
))
{
LOG
(
"removing directory: %s
\n
"
,(
char
*
)
name
);
deleteFromList
(
directory
->
subDirectories
,
node
->
key
);
deleteFromList
(
directory
->
subDirectories
,
node
->
key
);
}
}
else
{
LOG
(
"removing directory: %s
\n
"
,(
char
*
)
name
);
LOG
(
"removing directory: "
);
if
(
directory
->
utf8name
)
LOG
(
"%s/"
,
directory
->
utf8name
);
LOG
(
"%s
\n
"
,
node
->
key
);
deleteFromList
(
directory
->
subDirectories
,
node
->
key
);
}
node
=
tmpNode
;
...
...
@@ -360,39 +362,104 @@ int removeDeletedFromDirectory(Directory * directory) {
return
0
;
}
Directory
*
addDirectoryPathToDB
(
char
*
utf8path
,
char
**
shortname
)
{
char
*
parent
;
Directory
*
parentDirectory
;
void
*
directory
;
parent
=
strdup
(
parentPath
(
utf8path
));
if
(
strlen
(
parent
)
==
0
)
parentDirectory
=
(
void
*
)
mp3rootDirectory
;
else
parentDirectory
=
addDirectoryPathToDB
(
parent
,
shortname
);
*
shortname
=
utf8path
+
strlen
(
parent
);
while
(
*
(
*
shortname
)
&&
*
(
*
shortname
)
==
'/'
)
(
*
shortname
)
++
;
if
(
!
findInList
(
parentDirectory
->
subDirectories
,
*
shortname
,
&
directory
))
{
directory
=
(
void
*
)
addSubDirectoryToDirectory
(
parentDirectory
,
*
shortname
,
utf8path
);
}
/* if we're adding directory paths, make sure to delete filenames
with potentially the same name*/
removeSongFromDirectory
(
parentDirectory
,
*
shortname
);
free
(
parent
);
return
(
Directory
*
)
parentDirectory
;
}
Directory
*
addParentPathToDB
(
char
*
utf8path
,
char
**
shortname
)
{
char
*
parent
;
Directory
*
parentDirectory
;
parent
=
strdup
(
parentPath
(
utf8path
));
if
(
strlen
(
parent
)
==
0
)
parentDirectory
=
(
void
*
)
mp3rootDirectory
;
else
parentDirectory
=
addDirectoryPathToDB
(
parent
,
shortname
);
*
shortname
=
utf8path
+
strlen
(
parent
);
while
(
*
(
*
shortname
)
&&
*
(
*
shortname
)
==
'/'
)
(
*
shortname
)
++
;
free
(
parent
);
return
(
Directory
*
)
parentDirectory
;
}
void
updatePath
(
char
*
utf8path
)
{
Directory
*
directory
;
Directory
*
parentDirectory
;
Song
*
song
;
char
*
shortname
;
DIR
*
dir
;
char
*
path
=
sanitizePathDup
(
utf8path
);
if
(
NULL
==
path
)
return
;
/* if path is in the DB try to update it, or else delete it */
if
((
directory
=
getDirectoryDetails
(
utf8
path
,
&
shortname
,
if
((
directory
=
getDirectoryDetails
(
path
,
&
shortname
,
&
parentDirectory
)))
{
/* if
updateDirectory fials, means we should delete it
*/
if
(
updateDirectory
(
directory
)
<
0
&&
directory
!=
mp3rootDirectory
)
/* if
this update directory is successfull, we are done
*/
if
(
updateDirectory
(
directory
)
==
0
)
{
free
(
path
);
sortDirectory
(
directory
);
return
;
}
/* we don't want to delete the root directory */
else
if
(
directory
==
mp3rootDirectory
)
{
free
(
path
);
return
;
}
/* if updateDirectory fials, means we should delete it */
else
{
LOG
(
"removing directory: %s
\n
"
,
path
);
deleteFromList
(
parentDirectory
->
subDirectories
,
shortname
);
}
}
else
if
((
song
=
getSongDetails
(
utf8path
,
&
shortname
,
&
parentDirectory
)))
{
if
(
song
&&
updateSongInfo
(
song
)
<
0
)
{
removeSongFromDirectory
(
parentDirectory
,
shortname
);
else
if
((
song
=
getSongDetails
(
path
,
&
shortname
,
&
parentDirectory
)))
{
/* if this song update is successfull, we are done */
if
(
song
&&
updateSongInfo
(
song
)
==
0
)
{
free
(
path
);
return
;
}
/* if updateDirectory fials, means we should delete it */
else
removeSongFromDirectory
(
parentDirectory
,
shortname
);
}
/* apth not found in the db, see if it actually exists on the fs */
else
if
(
isDir
(
utf8path
,
NULL
))
{
/* create parent/get parent directory */
/* create new directory and add to parent */
/* explore direcotry
*/
}
else
if
((
isMusic
(
utf8path
,
NULL
)))
{
/* create parent/get parent directory */
/* add song to directory */
/* path not found in the db, see if it actually exists on the fs.
* Also, if by chance a directory was replaced by a file of the same
* name or vice versa, we need to add it to the db
*/
if
(
isDir
(
path
,
NULL
)
||
isMusic
(
path
,
NULL
))
{
parentDirectory
=
addParentPathToDB
(
path
,
&
shortname
);
addToDirectory
(
parentDirectory
,
shortname
,
path
);
sortDirectory
(
parentDirectory
);
}
free
(
path
);
}
int
updateDirectory
(
Directory
*
directory
)
{
...
...
@@ -479,7 +546,7 @@ int exploreDirectory(Directory * directory) {
return
0
;
}
int
addSubDirectoryToDirectory
(
Directory
*
directory
,
char
*
shortname
,
Directory
*
addSubDirectoryToDirectory
(
Directory
*
directory
,
char
*
shortname
,
char
*
name
)
{
Directory
*
subDirectory
=
newDirectory
(
name
,
-
1
);
...
...
@@ -487,12 +554,13 @@ int addSubDirectoryToDirectory(Directory * directory, char * shortname,
insertInList
(
directory
->
subDirectories
,
shortname
,
subDirectory
);
exploreDirectory
(
subDirectory
);
return
0
;
return
subDirectory
;
}
int
addToDirectory
(
Directory
*
directory
,
char
*
shortname
,
char
*
name
)
{
if
(
isDir
(
name
,
NULL
))
{
return
addSubDirectoryToDirectory
(
directory
,
shortname
,
name
);
addSubDirectoryToDirectory
(
directory
,
shortname
,
name
);
return
0
;
}
else
if
(
isMusic
(
name
,
NULL
))
{
Song
*
song
;
...
...
src/path.c
View file @
2a24a94b
...
...
@@ -20,6 +20,7 @@
#include "log.h"
#include "charConv.h"
#include "conf.h"
#include "utf8.h"
#include <stdlib.h>
#include <string.h>
...
...
@@ -202,3 +203,41 @@ char * parentPath(char * path) {
return
parentPath
;
}
char
*
sanitizePathDup
(
char
*
path
)
{
int
len
=
strlen
(
path
)
+
1
;
char
*
ret
=
malloc
(
len
);
char
*
cp
=
ret
;
memset
(
ret
,
0
,
len
);
len
=
0
;
/* illeminate more than one '/' in a row, like "///" */
while
(
*
path
)
{
while
(
*
path
==
'/'
)
path
++
;
if
(
*
path
==
'.'
)
{
/* we dont want to have hidden directoires, or '.' or
".." in our path */
free
(
ret
);
return
NULL
;
}
while
(
*
path
&&
*
path
!=
'/'
)
{
*
(
cp
++
)
=
*
(
path
++
);
len
++
;
}
if
(
*
path
==
'/'
)
{
*
(
cp
++
)
=
*
(
path
++
);
len
++
;
}
}
if
(
len
&&
ret
[
len
-
1
]
==
'/'
)
{
len
--
;
ret
[
len
]
=
'\0'
;
}
printf
(
"sanitized: %s
\n
"
,
ret
);
return
realloc
(
ret
,
len
+
1
);
}
src/path.h
View file @
2a24a94b
...
...
@@ -49,4 +49,7 @@ char * rpp2app(char * file);
/* static char * returned */
char
*
parentPath
(
char
*
path
);
/* strips extra "///" and leading "/" and trailing "/" */
char
*
sanitizePathDup
(
char
*
path
);
#endif
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