Loading...
Searching...
No Matches
do_copy.c
Go to the documentation of this file.
/*!
\file lib/manage/do_copy.c
\brief Manage Library - Copy element
(C) 2001-2011 by the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
\author Original author CERL
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <grass/gis.h>
#include <grass/glocale.h>
#include <grass/vector.h>
#include "manage_local_proto.h"
/*!
\brief Copy element
\param n element id
\param old source name
\param mapset name of source mapset
\param new destination name
\return 0 on success
\return 1 on error
*/
int M_do_copy(int n, const char *old, const char *mapset, const char *new)
{
int i, ret;
char path[GPATH_MAX], path2[GPATH_MAX];
int result = 0;
char *mname = G_fully_qualified_name(old, mapset);
G_debug(3, "Copy %s", list[n].alias);
G_message(_("Copying %s <%s> to current mapset as <%s>"), list[n].maindesc,
mname, new);
M__hold_signals(1);
if (G_strcasecmp(list[n].alias, "vector") == 0) {
ret = Vect_copy(old, mapset, new);
if (ret == -1) {
G_warning(_("Unable to copy <%s> to current mapset as <%s>"), mname,
new);
result = 1;
}
}
else {
for (i = 0; i < list[n].nelem; i++) {
G_make_mapset_object_group(list[n].element[i]);
G_file_name(path, list[n].element[i], old, mapset);
if (access(path, 0) != 0) {
G_remove(list[n].element[i], new);
G_verbose_message(_("%s is missing"), list[n].desc[i]);
continue;
}
G_file_name(path2, list[n].element[i], new, G_mapset());
if (G_recursive_copy(path, path2) == 1) {
G_warning(_("Unable to copy <%s> to current mapset as <%s>"),
mname, new);
result = 1;
}
else {
G_verbose_message(_("%s copied"), list[n].desc[i]);
}
}
}
/* special case: remove (yes, remove) the secondary color table, if it
* exists */
if (G_strcasecmp(list[n].element[0], "cell") == 0) {
char colr2[6 + GMAPSET_MAX];
if (snprintf(colr2, 6 + GMAPSET_MAX, "colr2/%s", G_mapset()) >=
6 + GMAPSET_MAX)
G_warning(_("String for secondary color table has been truncated"));
G_remove(colr2, new);
}
M__hold_signals(0);
G_free(mname);
return result;
}
G_free
void G_free(void *buf)
Free allocated memory.
Definition alloc.c:147
G_recursive_copy
int G_recursive_copy(const char *src, const char *dst)
Copy recursively source directory to destination directory.
Definition copy_dir.c:69
G_debug
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition debug.c:66
M_do_copy
int M_do_copy(int n, const char *old, const char *mapset, const char *new)
Copy element.
Definition do_copy.c:35
G_file_name
char * G_file_name(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files.
Definition file_name.c:61
G_verbose_message
void G_verbose_message(const char *msg,...)
Print a message to stderr but only if module is in verbose mode.
Definition gis/error.c:108
G_message
void G_message(const char *msg,...)
Print a message to stderr.
Definition gis/error.c:89
G_warning
void G_warning(const char *msg,...)
Print a warning message to stderr.
Definition gis/error.c:203
G_mapset
const char * G_mapset(void)
Get current mapset name.
Definition mapset.c:33
G_make_mapset_object_group
int G_make_mapset_object_group(const char *type)
Create directory for group of elements of a given type.
Definition mapset_msc.c:75
G_fully_qualified_name
char * G_fully_qualified_name(const char *name, const char *mapset)
Get fully qualified element name.
Definition nme_in_mps.c:101
list
struct list * list
Definition read_list.c:24
G_remove
int G_remove(const char *element, const char *name)
Remove a database file.
Definition remove.c:43
M__hold_signals
int M__hold_signals(int hold)
Hold signals.
Definition sighold.c:24
G_strcasecmp
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower).
Definition strings.c:47
element
Definition lidar.h:85
path
Definition path.h:15