diff options
| author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2024-08-13 17:57:24 -0400 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-13 17:57:24 -0400 | 
| commit | 683b3f78663efcff7a406d8287b78d73f18cc1f1 (patch) | |
| tree | 448cd01d092db0d3c8ecbc59729e7d76cbf06b04 | |
| parent | d943633d4d925d7340708371be8abb09adf579fe (diff) | |
| download | stasis-683b3f78663efcff7a406d8287b78d73f18cc1f1.tar.gz | |
Remove unused copytree() function (#27)
* Functionality was replaced by rsync long ago
| -rw-r--r-- | include/copy.h | 18 | ||||
| -rw-r--r-- | src/copy.c | 84 | 
2 files changed, 0 insertions, 102 deletions
| diff --git a/include/copy.h b/include/copy.h index a26ac30..0f92ddd 100644 --- a/include/copy.h +++ b/include/copy.h @@ -14,24 +14,6 @@  #define CT_PERM 1 << 2  /** - * Recursively copy a directory, or a single file - * - * ```c - * if (copytree("/source/path", "/destination/path", CT_PERM | CT_OWNER)) { - *     fprintf(stderr, "Unable to copy files\n"); - *     exit(1); - * } - * ``` - * - * @param srcdir source file or directory path - * @param destdir destination directory - * @param op CT_OWNER (preserve ownership) - * @param op CT_PERM (preserve permission bits) - * @return 0 on success, -1 on error - */ -int copytree(const char *srcdir, const char *destdir, unsigned op); - -/**   * Copy a single file   *   * ```c @@ -84,87 +84,3 @@ int copy2(const char *src, const char *dest, unsigned int op) {      }      return 0;  } - -int copytree(const char *srcdir, const char *destdir, unsigned int op) { -    DIR *dir; -    struct dirent *d; -    struct stat st; -    mode_t mode; -    mode_t umask_value; -    errno = 0; - -    dir = opendir(srcdir); -    if (!dir) { -        return -1; -    } - -    umask_value = umask(0); -    umask(umask_value); - -    if (lstat(srcdir, &st) < 0) { -        perror(srcdir); -        closedir(dir); -        return -1; -    } - -    if (op & CT_PERM) { -        mode = st.st_mode; -    } else { -        mode = 0777 & ~umask_value; -    } - -    // Source directory is not writable so modify the mode for the destination -    if (mode & ~S_IWUSR) { -        mode |= S_IWUSR; -    } - -    if (access(destdir, F_OK) < 0) { -        if (mkdirs(destdir, mode) < 0) { -            perror(destdir); -            closedir(dir); -            return -1; -        } -    } - -    memset(&st, 0, sizeof(st)); -    while ((d = readdir(dir)) != NULL) { -        char src[PATH_MAX] = {0}; -        char dest[PATH_MAX] = {0}; -        if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) { -            continue; -        } -        strcat(src, srcdir); -        strcat(src, "/"); -        strcat(src, d->d_name); - -        strcat(dest, destdir); -        strcat(dest, "/"); -        strcat(dest, d->d_name); - -        if (lstat(src, &st) < 0) { -            perror(srcdir); -            closedir(dir); -            return -1; -        } - -        if (d->d_type == DT_DIR) { -            if (strncmp(src, dest, strlen(src)) == 0) { -                closedir(dir); -                return -1; -            } - -            if (access(dest, F_OK) < 0) { -                if (mkdir(dest, mode) < 0) { -                    perror(dest); -                    closedir(dir); -                    return -1; -                } -            } - -            copytree(src, dest, op); -        } -        copy2(src, dest, op); -    } -    closedir(dir); -    return 0; -} | 
