cpdir.c (18b51f792fb28f3909a1e3a6b44898572b9afdcf) | cpdir.c (1b692a8c4495ea028986e0fd9ba81b156328a17e) |
---|---|
1/*- 2 * Copyright (C) 1996 3 * David L. Nugent. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 34 unchanged lines hidden (view full) --- 43 44#include "pwupd.h" 45 46void 47copymkdir(char const * dir, char const * skel, mode_t mode, uid_t uid, gid_t gid) 48{ 49 char src[MAXPATHLEN]; 50 char dst[MAXPATHLEN]; | 1/*- 2 * Copyright (C) 1996 3 * David L. Nugent. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 34 unchanged lines hidden (view full) --- 43 44#include "pwupd.h" 45 46void 47copymkdir(char const * dir, char const * skel, mode_t mode, uid_t uid, gid_t gid) 48{ 49 char src[MAXPATHLEN]; 50 char dst[MAXPATHLEN]; |
51 char lnk[MAXPATHLEN]; 52 int len; |
|
51 52 if (mkdir(dir, mode) != 0 && errno != EEXIST) { 53 warn("mkdir(%s)", dir); 54 } else { 55 int infd, outfd; 56 struct stat st; 57 58 static char counter = 0; --- 7 unchanged lines hidden (view full) --- 66 if (d != NULL) { 67 struct dirent *e; 68 69 while ((e = readdir(d)) != NULL) { 70 char *p = e->d_name; 71 72 if (snprintf(src, sizeof(src), "%s/%s", skel, p) >= (int)sizeof(src)) 73 warn("warning: pathname too long '%s/%s' (skel not copied)", skel, p); | 53 54 if (mkdir(dir, mode) != 0 && errno != EEXIST) { 55 warn("mkdir(%s)", dir); 56 } else { 57 int infd, outfd; 58 struct stat st; 59 60 static char counter = 0; --- 7 unchanged lines hidden (view full) --- 68 if (d != NULL) { 69 struct dirent *e; 70 71 while ((e = readdir(d)) != NULL) { 72 char *p = e->d_name; 73 74 if (snprintf(src, sizeof(src), "%s/%s", skel, p) >= (int)sizeof(src)) 75 warn("warning: pathname too long '%s/%s' (skel not copied)", skel, p); |
74 else if (stat(src, &st) == 0) { | 76 else if (lstat(src, &st) == 0) { |
75 if (strncmp(p, "dot.", 4) == 0) /* Conversion */ 76 p += 3; 77 if (snprintf(dst, sizeof(dst), "%s/%s", dir, p) >= (int)sizeof(dst)) 78 warn("warning: path too long '%s/%s' (skel file skipped)", dir, p); 79 else { 80 if (S_ISDIR(st.st_mode)) { /* Recurse for this */ 81 if (strcmp(e->d_name, ".") != 0 && strcmp(e->d_name, "..") != 0) 82 copymkdir(dst, src, (st.st_mode & 0777), uid, gid); 83 chflags(dst, st.st_flags); /* propogate flags */ | 77 if (strncmp(p, "dot.", 4) == 0) /* Conversion */ 78 p += 3; 79 if (snprintf(dst, sizeof(dst), "%s/%s", dir, p) >= (int)sizeof(dst)) 80 warn("warning: path too long '%s/%s' (skel file skipped)", dir, p); 81 else { 82 if (S_ISDIR(st.st_mode)) { /* Recurse for this */ 83 if (strcmp(e->d_name, ".") != 0 && strcmp(e->d_name, "..") != 0) 84 copymkdir(dst, src, (st.st_mode & 0777), uid, gid); 85 chflags(dst, st.st_flags); /* propogate flags */ |
86 } else if (S_ISLNK(st.st_mode) && (len = readlink(src, lnk, sizeof(lnk))) != -1) { 87 lnk[len] = '\0'; 88 symlink(lnk, dst); 89 lchown(dst, uid, gid); |
|
84 /* 85 * Note: don't propogate special attributes 86 * but do propogate file flags 87 */ 88 } else if (S_ISREG(st.st_mode) && (outfd = open(dst, O_RDWR | O_CREAT | O_EXCL, st.st_mode)) != -1) { 89 if ((infd = open(src, O_RDONLY)) == -1) { 90 close(outfd); 91 remove(dst); --- 33 unchanged lines hidden --- | 90 /* 91 * Note: don't propogate special attributes 92 * but do propogate file flags 93 */ 94 } else if (S_ISREG(st.st_mode) && (outfd = open(dst, O_RDWR | O_CREAT | O_EXCL, st.st_mode)) != -1) { 95 if ((infd = open(src, O_RDONLY)) == -1) { 96 close(outfd); 97 remove(dst); --- 33 unchanged lines hidden --- |