12 #include <grass/config.h>
18 #include <sys/types.h>
20 #include <grass/gis.h>
21 #include <grass/glocale.h>
23 static int make_mapset_element(
const char *,
const char *);
24 static int make_mapset_element_no_fail_on_race(
const char *,
const char *);
25 static int make_mapset_element_impl(
const char *,
const char *,
bool);
50 return make_mapset_element(
path, p_element);
80 return make_mapset_element_no_fail_on_race(
path, type);
111 char path[GPATH_MAX];
115 return make_mapset_element(
path,
name);
134 char path[GPATH_MAX];
137 return make_mapset_element(
path, p_element);
156 char path[GPATH_MAX];
159 return make_mapset_element_no_fail_on_race(
path, type);
178 char path[GPATH_MAX];
181 return make_mapset_element_no_fail_on_race(
path, type);
184 int make_mapset_element_impl(
const char *p_path,
const char *p_element,
187 char path[GPATH_MAX] = {
'\0'};
195 strncpy(
path, p_path, GPATH_MAX - 1);
212 if (access(
path, 0) != 0) {
215 msg =
G_store(strerror(errno));
218 if (access(
path, 0) != 0 || (msg && !race_ok)) {
224 _(
"Unable to make mapset element %s (%s): %s"),
225 p_element,
path, strerror(errno));
230 _(
"Unable to access mapset element %s (%s): %s"),
231 p_element,
path, strerror(errno));
241 int make_mapset_element(
const char *p_path,
const char *p_element)
243 return make_mapset_element_impl(p_path, p_element,
false);
246 int make_mapset_element_no_fail_on_race(
const char *p_path,
247 const char *p_element)
249 return make_mapset_element_impl(p_path, p_element,
true);
266 static int check_owner(
const struct stat *info)
268 #if defined(_WIN32) || defined(SKIP_MAPSET_OWN_CHK)
271 const char *check = getenv(
"GRASS_SKIP_MAPSET_OWNER_CHECK");
275 if (info->st_uid != getuid())
277 if (info->st_uid != geteuid())
294 char path[GPATH_MAX];
301 if (!S_ISDIR(info.st_mode))
304 if (!check_owner(&info))
324 char path[GPATH_MAX];
327 snprintf(
path,
sizeof(
path),
"%s/%s/%s", gisdbase, location, mapset);
331 if (!S_ISDIR(info.st_mode))
334 if (!check_owner(&info))
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(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files.
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.