12#include <grass/config.h>
20#include <grass/glocale.h>
22static int make_mapset_element(
const char *,
const char *);
23static int make_mapset_element_no_fail_on_race(
const char *,
const char *);
24static int make_mapset_element_impl(
const char *,
const char *,
bool);
49 return make_mapset_element(
path, p_element);
79 return make_mapset_element_no_fail_on_race(
path, type);
110 char path[GPATH_MAX];
114 return make_mapset_element(
path,
name);
133 char path[GPATH_MAX];
136 return make_mapset_element(
path, p_element);
155 char path[GPATH_MAX];
158 return make_mapset_element_no_fail_on_race(
path, type);
177 char path[GPATH_MAX];
180 return make_mapset_element_no_fail_on_race(
path, type);
183int make_mapset_element_impl(
const char *p_path,
const char *p_element,
186 char path[GPATH_MAX] = {
'\0'};
194 strncpy(
path, p_path, GPATH_MAX - 1);
211 if (access(
path, 0) != 0) {
214 msg =
G_store(strerror(errno));
217 if (access(
path, 0) != 0 || (msg && !race_ok)) {
223 _(
"Unable to make mapset element %s (%s): %s"),
224 p_element,
path, strerror(errno));
229 _(
"Unable to access mapset element %s (%s): %s"),
230 p_element,
path, strerror(errno));
240int make_mapset_element(
const char *p_path,
const char *p_element)
242 return make_mapset_element_impl(p_path, p_element,
false);
245int make_mapset_element_no_fail_on_race(
const char *p_path,
246 const char *p_element)
248 return make_mapset_element_impl(p_path, p_element,
true);
265static int check_owner(
const struct stat *info)
267#if defined(__MINGW32__) || defined(SKIP_MAPSET_OWN_CHK)
270 const char *check = getenv(
"GRASS_SKIP_MAPSET_OWNER_CHECK");
274 if (info->st_uid != getuid())
276 if (info->st_uid != geteuid())
293 char path[GPATH_MAX];
300 if (!S_ISDIR(info.st_mode))
303 if (!check_owner(&info))
323 char path[GPATH_MAX];
326 sprintf(
path,
"%s/%s/%s", gisdbase, location, mapset);
330 if (!S_ISDIR(info.st_mode))
333 if (!check_owner(&info))
char * G_file_name(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files.
char * G_file_name_basedir(char *path, const char *element, const char *name, const char *mapset, const char *basedir)
Builds full path names to GIS data files in temporary directory (for internal use only)
char * G_file_name_tmp(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files in temporary directory (for internal use only)
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
const char * G_mapset(void)
Get current mapset name.
int G_make_mapset_object_group_tmp(const char *type)
Create directory for type of objects in the temporary directory.
int G__make_mapset_element_misc(const char *dir, const char *name)
Create misc element in the current mapset.
int G_mapset_permissions2(const char *gisdbase, const char *location, const char *mapset)
Check for user mapset permission.
int G_make_mapset_object_group(const char *type)
Create directory for group of elements of a given type.
int G_mapset_permissions(const char *mapset)
Check for user mapset permission.
int G_make_mapset_dir_object(const char *type, const char *name)
Create directory for an object of a given type.
int G_make_mapset_element(const char *p_element)
Create element in the current mapset.
int G_make_mapset_element_tmp(const char *p_element)
Create element in the temporary directory.
int G_make_mapset_object_group_basedir(const char *type, const char *basedir)
Create directory for type of objects in the temporary directory.
int G_mkdir(const char *path)
Creates a new directory.
int G_stat(const char *file_name, struct stat *buf)
Get file status.
char * G_store(const char *s)
Copy string to allocated memory.