GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
copy_dir.c File Reference

GIS Library - function to recursively copy a directory. More...

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <grass/gis.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
Include dependency graph for copy_dir.c:

Go to the source code of this file.

Functions

int G_recursive_copy (const char *src, const char *dst)
 Copy recursively source directory to destination directory. More...
 

Detailed Description

GIS Library - function to recursively copy a directory.

Extracted from general/manage/lib/do_copy.c

(C) 2008-2015 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
Huidae Cho

Definition in file copy_dir.c.

Function Documentation

◆ G_recursive_copy()

int G_recursive_copy ( const char *  src,
const char *  dst 
)

Copy recursively source directory to destination directory.

RULE:

  1. If destination does not exist, copy source to destination as expected.
  2. If destination already exists and it's a file, destination will be deleted first and apply RULE 1.
  3. If destination already exists which is a directory and source is a file, try to copy source to destination directory.
  4. If destination already exists which is a directory and source is also a directory, try to copy all contents in source to destination directory.

This rule is designed according to general/manage/lib/copy.sh.

POSSIBLE CASES:

* if src is a file:
*      if dst does not exist:
*              copy src to dst                         RULE 1
*      if dst is a file:
*              delete dst and copy src to dst          RULE 2
*      if dst is a directory:
*              try recursive_copy(src, dst/src)        RULE 3
* if src is a directory:
*      if dst does not exist:
*              copy src to dst                         RULE 1
*      if dst is a file:
*              delete dst and copy src to dst          RULE 2
*      if dst is a directory:
*              try                                     RULE 4
*              for i in `ls src`
*              do
*                      recursive_copy(src/$i, dst/$i)
*              done
* 
Parameters
srcsource directory
dstdestination directory
Returns
0 if successful, otherwise 1

Definition at line 70 of file copy_dir.c.

Referenced by M_do_copy(), and V1_close_nat().