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
6fd7d819
Commit
6fd7d819
authored
Mar 18, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/simple: refactor Check() to throw exception
parent
2ccd1cc9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
36 deletions
+23
-36
SimpleDatabasePlugin.cxx
src/db/plugins/simple/SimpleDatabasePlugin.cxx
+22
-35
SimpleDatabasePlugin.hxx
src/db/plugins/simple/SimpleDatabasePlugin.hxx
+1
-1
No files found.
src/db/plugins/simple/SimpleDatabasePlugin.cxx
View file @
6fd7d819
...
@@ -113,8 +113,8 @@ SimpleDatabase::Configure(const ConfigBlock &block, Error &error)
...
@@ -113,8 +113,8 @@ SimpleDatabase::Configure(const ConfigBlock &block, Error &error)
return
true
;
return
true
;
}
}
bool
void
SimpleDatabase
::
Check
(
Error
&
error
)
const
SimpleDatabase
::
Check
()
const
{
{
assert
(
!
path
.
IsNull
());
assert
(
!
path
.
IsNull
());
...
@@ -127,54 +127,43 @@ SimpleDatabase::Check(Error &error) const
...
@@ -127,54 +127,43 @@ SimpleDatabase::Check(Error &error) const
/* Check that the parent part of the path is a directory */
/* Check that the parent part of the path is a directory */
FileInfo
fi
;
FileInfo
fi
;
if
(
!
GetFileInfo
(
dirPath
,
fi
,
error
))
{
error
.
AddPrefix
(
"On parent directory of db file: "
);
return
false
;
}
if
(
!
fi
.
IsDirectory
())
{
try
{
error
.
Format
(
simple_db_domain
,
fi
=
FileInfo
(
dirPath
);
"Couldn't create db file
\"
%s
\"
because the "
}
catch
(...)
{
"parent path is not a directory"
,
std
::
throw_with_nested
(
std
::
runtime_error
(
"On parent directory of db file"
));
path_utf8
.
c_str
());
return
false
;
}
}
if
(
!
fi
.
IsDirectory
())
throw
std
::
runtime_error
(
"Couldn't create db file
\"
"
+
path_utf8
+
"
\"
because the "
"parent path is not a directory"
);
#ifndef WIN32
#ifndef WIN32
/* Check if we can write to the directory */
/* Check if we can write to the directory */
if
(
!
CheckAccess
(
dirPath
,
X_OK
|
W_OK
))
{
if
(
!
CheckAccess
(
dirPath
,
X_OK
|
W_OK
))
{
const
int
e
=
errno
;
const
int
e
=
errno
;
const
std
::
string
dirPath_utf8
=
dirPath
.
ToUTF8
();
const
std
::
string
dirPath_utf8
=
dirPath
.
ToUTF8
();
error
.
FormatErrno
(
e
,
"Can't create db file in
\"
%s
\"
"
,
throw
FormatErrno
(
e
,
"Can't create db file in
\"
%s
\"
"
,
dirPath_utf8
.
c_str
());
dirPath_utf8
.
c_str
());
return
false
;
}
}
#endif
#endif
return
true
;
return
;
}
}
/* Path exists, now check if it's a regular file */
/* Path exists, now check if it's a regular file */
FileInfo
fi
;
const
FileInfo
fi
(
path
);
if
(
!
GetFileInfo
(
path
,
fi
,
error
))
return
false
;
if
(
!
fi
.
IsRegular
())
{
if
(
!
fi
.
IsRegular
())
error
.
Format
(
simple_db_domain
,
throw
std
::
runtime_error
(
"db file
\"
"
+
path_utf8
+
"
\"
is not a regular file"
);
"db file
\"
%s
\"
is not a regular file"
,
path_utf8
.
c_str
());
return
false
;
}
#ifndef WIN32
#ifndef WIN32
/* And check that we can write to it */
/* And check that we can write to it */
if
(
!
CheckAccess
(
path
,
R_OK
|
W_OK
))
{
if
(
!
CheckAccess
(
path
,
R_OK
|
W_OK
))
error
.
FormatErrno
(
"Can't open db file
\"
%s
\"
for reading/writing"
,
throw
FormatErrno
(
"Can't open db file
\"
%s
\"
for reading/writing"
,
path_utf8
.
c_str
());
path_utf8
.
c_str
());
return
false
;
}
#endif
#endif
return
true
;
}
}
bool
bool
...
@@ -196,7 +185,7 @@ SimpleDatabase::Load(Error &error)
...
@@ -196,7 +185,7 @@ SimpleDatabase::Load(Error &error)
}
}
bool
bool
SimpleDatabase
::
Open
(
Error
&
error
)
SimpleDatabase
::
Open
(
gcc_unused
Error
&
error
)
{
{
assert
(
prefixed_light_song
==
nullptr
);
assert
(
prefixed_light_song
==
nullptr
);
...
@@ -214,8 +203,7 @@ SimpleDatabase::Open(Error &error)
...
@@ -214,8 +203,7 @@ SimpleDatabase::Open(Error &error)
delete
root
;
delete
root
;
if
(
!
Check
(
error
))
Check
();
return
false
;
root
=
Directory
::
NewRoot
();
root
=
Directory
::
NewRoot
();
}
}
...
@@ -224,8 +212,7 @@ SimpleDatabase::Open(Error &error)
...
@@ -224,8 +212,7 @@ SimpleDatabase::Open(Error &error)
delete
root
;
delete
root
;
if
(
!
Check
(
error
))
Check
();
return
false
;
root
=
Directory
::
NewRoot
();
root
=
Directory
::
NewRoot
();
}
}
...
...
src/db/plugins/simple/SimpleDatabasePlugin.hxx
View file @
6fd7d819
...
@@ -136,7 +136,7 @@ public:
...
@@ -136,7 +136,7 @@ public:
private
:
private
:
bool
Configure
(
const
ConfigBlock
&
block
,
Error
&
error
);
bool
Configure
(
const
ConfigBlock
&
block
,
Error
&
error
);
bool
Check
(
Error
&
error
)
const
;
void
Check
(
)
const
;
bool
Load
(
Error
&
error
);
bool
Load
(
Error
&
error
);
...
...
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