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
3b620112
Commit
3b620112
authored
Feb 02, 2013
by
Denis Krjuchkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SimpleDatabasePlugin: use file system API, log in UTF-8
parent
99526219
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
25 deletions
+24
-25
SimpleDatabasePlugin.cxx
src/db/SimpleDatabasePlugin.cxx
+23
-25
SimpleDatabasePlugin.hxx
src/db/SimpleDatabasePlugin.hxx
+1
-0
No files found.
src/db/SimpleDatabasePlugin.cxx
View file @
3b620112
...
@@ -28,10 +28,9 @@
...
@@ -28,10 +28,9 @@
#include "db_error.h"
#include "db_error.h"
#include "TextFile.hxx"
#include "TextFile.hxx"
#include "conf.h"
#include "conf.h"
#include "fs/FileSystem.hxx"
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <errno.h>
G_GNUC_CONST
G_GNUC_CONST
...
@@ -69,6 +68,8 @@ SimpleDatabase::Configure(const struct config_param *param, GError **error_r)
...
@@ -69,6 +68,8 @@ SimpleDatabase::Configure(const struct config_param *param, GError **error_r)
}
}
path
=
Path
::
FromUTF8
(
_path
);
path
=
Path
::
FromUTF8
(
_path
);
path_utf8
=
_path
;
free
(
_path
);
free
(
_path
);
if
(
path
.
IsNull
())
{
if
(
path
.
IsNull
())
{
...
@@ -87,67 +88,64 @@ SimpleDatabase::Check(GError **error_r) const
...
@@ -87,67 +88,64 @@ SimpleDatabase::Check(GError **error_r) const
assert
(
!
path
.
empty
());
assert
(
!
path
.
empty
());
/* Check if the file exists */
/* Check if the file exists */
if
(
access
(
path
.
c_str
()
,
F_OK
))
{
if
(
!
CheckAccess
(
path
,
F_OK
))
{
/* If the file doesn't exist, we can't check if we can write
/* If the file doesn't exist, we can't check if we can write
* it, so we are going to try to get the directory path, and
* it, so we are going to try to get the directory path, and
* see if we can write a file in that */
* see if we can write a file in that */
c
har
*
dirPath
=
g_path_get_dirname
(
path
.
c_str
()
);
c
onst
Path
dirPath
=
path
.
GetDirectoryName
(
);
/* Check that the parent part of the path is a directory */
/* Check that the parent part of the path is a directory */
struct
stat
st
;
struct
stat
st
;
if
(
stat
(
dirPath
,
&
st
)
<
0
)
{
if
(
!
StatFile
(
dirPath
,
st
))
{
g_free
(
dirPath
);
g_set_error
(
error_r
,
simple_db_quark
(),
errno
,
g_set_error
(
error_r
,
simple_db_quark
(),
errno
,
"Couldn't stat parent directory of db file "
"Couldn't stat parent directory of db file "
"
\"
%s
\"
: %s"
,
"
\"
%s
\"
: %s"
,
path
.
c_str
(),
g_strerror
(
errno
));
path
_utf8
.
c_str
(),
g_strerror
(
errno
));
return
false
;
return
false
;
}
}
if
(
!
S_ISDIR
(
st
.
st_mode
))
{
if
(
!
S_ISDIR
(
st
.
st_mode
))
{
g_free
(
dirPath
);
g_set_error
(
error_r
,
simple_db_quark
(),
0
,
g_set_error
(
error_r
,
simple_db_quark
(),
0
,
"Couldn't create db file
\"
%s
\"
because the "
"Couldn't create db file
\"
%s
\"
because the "
"parent path is not a directory"
,
"parent path is not a directory"
,
path
.
c_str
());
path
_utf8
.
c_str
());
return
false
;
return
false
;
}
}
/* Check if we can write to the directory */
/* Check if we can write to the directory */
if
(
access
(
dirPath
,
X_OK
|
W_OK
))
{
if
(
!
CheckAccess
(
dirPath
,
X_OK
|
W_OK
))
{
g_set_error
(
error_r
,
simple_db_quark
(),
errno
,
int
error
=
errno
;
const
std
::
string
dirPath_utf8
=
dirPath
.
ToUTF8
();
g_set_error
(
error_r
,
simple_db_quark
(),
error
,
"Can't create db file in
\"
%s
\"
: %s"
,
"Can't create db file in
\"
%s
\"
: %s"
,
dirPath
,
g_strerror
(
errno
));
dirPath_utf8
.
c_str
(),
g_strerror
(
error
));
g_free
(
dirPath
);
return
false
;
return
false
;
}
}
g_free
(
dirPath
);
return
true
;
return
true
;
}
}
/* Path exists, now check if it's a regular file */
/* Path exists, now check if it's a regular file */
struct
stat
st
;
struct
stat
st
;
if
(
stat
(
path
.
c_str
(),
&
st
)
<
0
)
{
if
(
!
StatFile
(
path
,
st
)
)
{
g_set_error
(
error_r
,
simple_db_quark
(),
errno
,
g_set_error
(
error_r
,
simple_db_quark
(),
errno
,
"Couldn't stat db file
\"
%s
\"
: %s"
,
"Couldn't stat db file
\"
%s
\"
: %s"
,
path
.
c_str
(),
g_strerror
(
errno
));
path
_utf8
.
c_str
(),
g_strerror
(
errno
));
return
false
;
return
false
;
}
}
if
(
!
S_ISREG
(
st
.
st_mode
))
{
if
(
!
S_ISREG
(
st
.
st_mode
))
{
g_set_error
(
error_r
,
simple_db_quark
(),
0
,
g_set_error
(
error_r
,
simple_db_quark
(),
0
,
"db file
\"
%s
\"
is not a regular file"
,
"db file
\"
%s
\"
is not a regular file"
,
path
.
c_str
());
path
_utf8
.
c_str
());
return
false
;
return
false
;
}
}
/* And check that we can write to it */
/* And check that we can write to it */
if
(
access
(
path
.
c_str
()
,
R_OK
|
W_OK
))
{
if
(
!
CheckAccess
(
path
,
R_OK
|
W_OK
))
{
g_set_error
(
error_r
,
simple_db_quark
(),
errno
,
g_set_error
(
error_r
,
simple_db_quark
(),
errno
,
"Can't open db file
\"
%s
\"
for reading/writing: %s"
,
"Can't open db file
\"
%s
\"
for reading/writing: %s"
,
path
.
c_str
(),
g_strerror
(
errno
));
path
_utf8
.
c_str
(),
g_strerror
(
errno
));
return
false
;
return
false
;
}
}
...
@@ -164,7 +162,7 @@ SimpleDatabase::Load(GError **error_r)
...
@@ -164,7 +162,7 @@ SimpleDatabase::Load(GError **error_r)
if
(
file
.
HasFailed
())
{
if
(
file
.
HasFailed
())
{
g_set_error
(
error_r
,
simple_db_quark
(),
errno
,
g_set_error
(
error_r
,
simple_db_quark
(),
errno
,
"Failed to open database file
\"
%s
\"
: %s"
,
"Failed to open database file
\"
%s
\"
: %s"
,
path
.
c_str
(),
g_strerror
(
errno
));
path
_utf8
.
c_str
(),
g_strerror
(
errno
));
return
false
;
return
false
;
}
}
...
@@ -172,7 +170,7 @@ SimpleDatabase::Load(GError **error_r)
...
@@ -172,7 +170,7 @@ SimpleDatabase::Load(GError **error_r)
return
false
;
return
false
;
struct
stat
st
;
struct
stat
st
;
if
(
stat
(
path
.
c_str
(),
&
st
)
==
0
)
if
(
StatFile
(
path
,
st
)
)
mtime
=
st
.
st_mtime
;
mtime
=
st
.
st_mtime
;
return
true
;
return
true
;
...
@@ -318,11 +316,11 @@ SimpleDatabase::Save(GError **error_r)
...
@@ -318,11 +316,11 @@ SimpleDatabase::Save(GError **error_r)
g_debug
(
"writing DB"
);
g_debug
(
"writing DB"
);
FILE
*
fp
=
fopen
(
path
.
c_str
(),
"w"
);
FILE
*
fp
=
FOpen
(
path
,
FOpenMode
::
WriteText
);
if
(
!
fp
)
{
if
(
!
fp
)
{
g_set_error
(
error_r
,
simple_db_quark
(),
errno
,
g_set_error
(
error_r
,
simple_db_quark
(),
errno
,
"unable to write to db file
\"
%s
\"
: %s"
,
"unable to write to db file
\"
%s
\"
: %s"
,
path
.
c_str
(),
g_strerror
(
errno
));
path
_utf8
.
c_str
(),
g_strerror
(
errno
));
return
false
;
return
false
;
}
}
...
@@ -339,7 +337,7 @@ SimpleDatabase::Save(GError **error_r)
...
@@ -339,7 +337,7 @@ SimpleDatabase::Save(GError **error_r)
fclose
(
fp
);
fclose
(
fp
);
struct
stat
st
;
struct
stat
st
;
if
(
stat
(
path
.
c_str
(),
&
st
)
==
0
)
if
(
StatFile
(
path
,
st
)
)
mtime
=
st
.
st_mtime
;
mtime
=
st
.
st_mtime
;
return
true
;
return
true
;
...
...
src/db/SimpleDatabasePlugin.hxx
View file @
3b620112
...
@@ -32,6 +32,7 @@ struct Directory;
...
@@ -32,6 +32,7 @@ struct Directory;
class
SimpleDatabase
:
public
Database
{
class
SimpleDatabase
:
public
Database
{
Path
path
;
Path
path
;
std
::
string
path_utf8
;
Directory
*
root
;
Directory
*
root
;
...
...
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