do_copy.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <unistd.h>
  4. #include <grass/gis.h>
  5. #include <grass/Vect.h>
  6. #include "list.h"
  7. /*
  8. * returns 0 - success
  9. * 1 - error
  10. */
  11. int do_copy(int n, char *old, char *mapset, char *new)
  12. {
  13. int i, ret, len;
  14. char path[GPATH_MAX], path2[GPATH_MAX];
  15. int result = 0;
  16. G_debug(3, "Copy %s", list[n].alias);
  17. G_message(_("Copy %s <%s> to current mapset as <%s>"),
  18. list[n].maindesc, G_fully_qualified_name(old, mapset), new);
  19. len = get_description_len(n);
  20. hold_signals(1);
  21. if (G_strcasecmp(list[n].alias, "vect") == 0) {
  22. ret = Vect_copy(old, mapset, new);
  23. if (ret == -1) {
  24. G_warning("Cannot copy <%s> to current mapset as <%s>",
  25. G_fully_qualified_name(old, mapset), new);
  26. result = 1;
  27. }
  28. }
  29. else {
  30. for (i = 0; i < list[n].nelem; i++) {
  31. G__make_mapset_element(list[n].element[i]);
  32. G__file_name(path, list[n].element[i], old, mapset);
  33. if (access(path, 0) != 0) {
  34. G_remove(list[n].element[i], new);
  35. if (G_verbose() == G_verbose_max())
  36. G_message(_("%s: missing"), list[n].desc[i]);
  37. continue;
  38. }
  39. G__file_name(path2, list[n].element[i], new, G_mapset());
  40. if (G_recursive_copy(path, path2) == 1) {
  41. result = 1;
  42. }
  43. else {
  44. if (G_verbose() == G_verbose_max())
  45. G_message(_("%s: copied"), list[n].desc[i]);
  46. }
  47. }
  48. }
  49. /* special case: remove (yes, remove) the secondary color table, if it exists */
  50. if (G_strcasecmp(list[n].element[0], "cell") == 0) {
  51. char colr2[GNAME_MAX];
  52. sprintf(colr2, "colr2/%s", G_mapset());
  53. G_remove(colr2, new);
  54. }
  55. hold_signals(0);
  56. return result;
  57. }