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
5f2705ab
Commit
5f2705ab
authored
Sep 12, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ConfigPath: move code to GetHome()
parent
9af62098
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
28 deletions
+48
-28
ConfigPath.cxx
src/ConfigPath.cxx
+48
-28
No files found.
src/ConfigPath.cxx
View file @
5f2705ab
...
...
@@ -30,6 +30,49 @@
#ifndef WIN32
#include <pwd.h>
/**
* Determine a given user's home directory.
*/
static
const
char
*
GetHome
(
const
char
*
user
,
Error
&
error
)
{
passwd
*
pw
=
getpwnam
(
user
);
if
(
pw
==
nullptr
)
{
error
.
Format
(
path_domain
,
"no such user: %s"
,
user
);
return
nullptr
;
}
return
pw
->
pw_dir
;
}
/**
* Determine the current user's home directory.
*/
static
const
char
*
GetHome
(
Error
&
error
)
{
const
char
*
home
=
g_get_home_dir
();
if
(
home
==
nullptr
)
error
.
Set
(
path_domain
,
"problems getting home for current user"
);
return
home
;
}
/**
* Determine the configured user's home directory.
*/
static
const
char
*
GetConfiguredHome
(
Error
&
error
)
{
const
char
*
user
=
config_get_string
(
CONF_USER
,
nullptr
);
return
user
!=
nullptr
?
GetHome
(
user
,
error
)
:
GetHome
(
error
);
}
#endif
Path
...
...
@@ -50,25 +93,7 @@ ParsePath(const char *path, Error &error)
const
char
*
home
;
if
(
path
[
1
]
==
'/'
||
path
[
1
]
==
'\0'
)
{
const
char
*
user
=
config_get_string
(
CONF_USER
,
nullptr
);
if
(
user
!=
nullptr
)
{
struct
passwd
*
passwd
=
getpwnam
(
user
);
if
(
!
passwd
)
{
error
.
Format
(
path_domain
,
"no such user: %s"
,
user
);
return
Path
::
Null
();
}
home
=
passwd
->
pw_dir
;
}
else
{
home
=
g_get_home_dir
();
if
(
home
==
nullptr
)
{
error
.
Set
(
path_domain
,
"problems getting home "
"for current user"
);
return
Path
::
Null
();
}
}
home
=
GetConfiguredHome
(
error
);
++
path
;
}
else
{
...
...
@@ -79,20 +104,15 @@ ParsePath(const char *path, Error &error)
?
g_strndup
(
path
,
slash
-
path
)
:
g_strdup
(
path
);
struct
passwd
*
passwd
=
getpwnam
(
user
);
if
(
!
passwd
)
{
error
.
Format
(
path_domain
,
"no such user: %s"
,
user
);
home
=
GetHome
(
user
,
error
);
g_free
(
user
);
return
Path
::
Null
();
}
g_free
(
user
);
home
=
passwd
->
pw_dir
;
path
=
slash
;
}
if
(
home
==
nullptr
)
return
Path
::
Null
();
return
Path
::
Build
(
home
,
path2
);
}
else
{
#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