do_copy.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*!
  2. \file lib/manage/do_copy.c
  3. \brief Manage Library - Copy element
  4. (C) 2001-2011 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Original author CERL
  8. */
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <unistd.h>
  12. #include <grass/gis.h>
  13. #include <grass/glocale.h>
  14. #include <grass/vector.h>
  15. #include "manage_local_proto.h"
  16. /*!
  17. \brief Copy element
  18. \param n element id
  19. \param old source name
  20. \param mapset name of source mapset
  21. \param new destination name
  22. \return 0 on success
  23. \return 1 on error
  24. */
  25. int M_do_copy(int n, const char *old, const char *mapset, const char *new)
  26. {
  27. int i, ret, len;
  28. char path[GPATH_MAX], path2[GPATH_MAX];
  29. int result = 0;
  30. G_debug(3, "Copy %s", list[n].alias);
  31. G_message(_("Copy %s <%s> to current mapset as <%s>"),
  32. list[n].maindesc, G_fully_qualified_name(old, mapset), new);
  33. len = M__get_description_len(n);
  34. M__hold_signals(1);
  35. if (G_strcasecmp(list[n].alias, "vect") == 0) {
  36. ret = Vect_copy(old, mapset, new);
  37. if (ret == -1) {
  38. G_warning(_("Unable to copy <%s> to current mapset as <%s>"),
  39. G_fully_qualified_name(old, mapset), new);
  40. result = 1;
  41. }
  42. }
  43. else {
  44. for (i = 0; i < list[n].nelem; i++) {
  45. G__make_mapset_element(list[n].element[i]);
  46. G_file_name(path, list[n].element[i], old, mapset);
  47. if (access(path, 0) != 0) {
  48. G_remove(list[n].element[i], new);
  49. G_verbose_message(_("%s is missing"), list[n].desc[i]);
  50. continue;
  51. }
  52. G_file_name(path2, list[n].element[i], new, G_mapset());
  53. if (G_recursive_copy(path, path2) == 1) {
  54. result = 1;
  55. }
  56. else {
  57. G_verbose_message(_("%s copied"), list[n].desc[i]);
  58. }
  59. }
  60. }
  61. /* special case: remove (yes, remove) the secondary color table, if it exists */
  62. if (G_strcasecmp(list[n].element[0], "cell") == 0) {
  63. char colr2[GNAME_MAX];
  64. sprintf(colr2, "colr2/%s", G_mapset());
  65. G_remove(colr2, new);
  66. }
  67. M__hold_signals(0);
  68. return result;
  69. }