updater: Delete dead code
set_perm and set_perm_recursive are no longer used. Delete. Change-Id: I3bb40b934b6c093b24b88aa4ed6f3c7de2bb52f0
This commit is contained in:
parent
53e8f30918
commit
08ef9a9570
3 changed files with 0 additions and 153 deletions
|
@ -234,61 +234,3 @@ dirUnlinkHierarchy(const char *path)
|
|||
/* delete target directory */
|
||||
return rmdir(path);
|
||||
}
|
||||
|
||||
int
|
||||
dirSetHierarchyPermissions(const char *path,
|
||||
int uid, int gid, int dirMode, int fileMode)
|
||||
{
|
||||
struct stat st;
|
||||
if (lstat(path, &st)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ignore symlinks */
|
||||
if (S_ISLNK(st.st_mode)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* directories and files get different permissions */
|
||||
if (chown(path, uid, gid) ||
|
||||
chmod(path, S_ISDIR(st.st_mode) ? dirMode : fileMode)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* recurse over directory components */
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
DIR *dir = opendir(path);
|
||||
if (dir == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
const struct dirent *de;
|
||||
while (errno == 0 && (de = readdir(dir)) != NULL) {
|
||||
if (!strcmp(de->d_name, "..") || !strcmp(de->d_name, ".")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char dn[PATH_MAX];
|
||||
snprintf(dn, sizeof(dn), "%s/%s", path, de->d_name);
|
||||
if (!dirSetHierarchyPermissions(dn, uid, gid, dirMode, fileMode)) {
|
||||
errno = 0;
|
||||
} else if (errno == 0) {
|
||||
errno = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (errno != 0) {
|
||||
int save = errno;
|
||||
closedir(dir);
|
||||
errno = save;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (closedir(dir)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -48,14 +48,6 @@ int dirCreateHierarchy(const char *path, int mode,
|
|||
*/
|
||||
int dirUnlinkHierarchy(const char *path);
|
||||
|
||||
/* chown -R <uid>:<gid> <path>
|
||||
* chmod -R <mode> <path>
|
||||
*
|
||||
* Sets directories to <dirMode> and files to <fileMode>. Skips symlinks.
|
||||
*/
|
||||
int dirSetHierarchyPermissions(const char *path,
|
||||
int uid, int gid, int dirMode, int fileMode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -524,88 +524,6 @@ Value* SymlinkFn(const char* name, State* state, int argc, Expr* argv[]) {
|
|||
return StringValue(strdup(""));
|
||||
}
|
||||
|
||||
|
||||
Value* SetPermFn(const char* name, State* state, int argc, Expr* argv[]) {
|
||||
char* result = NULL;
|
||||
bool recursive = (strcmp(name, "set_perm_recursive") == 0);
|
||||
|
||||
int min_args = 4 + (recursive ? 1 : 0);
|
||||
if (argc < min_args) {
|
||||
return ErrorAbort(state, "%s() expects %d+ args, got %d",
|
||||
name, min_args, argc);
|
||||
}
|
||||
|
||||
char** args = ReadVarArgs(state, argc, argv);
|
||||
if (args == NULL) return NULL;
|
||||
|
||||
char* end;
|
||||
int i;
|
||||
int bad = 0;
|
||||
|
||||
int uid = strtoul(args[0], &end, 0);
|
||||
if (*end != '\0' || args[0][0] == 0) {
|
||||
ErrorAbort(state, "%s: \"%s\" not a valid uid", name, args[0]);
|
||||
goto done;
|
||||
}
|
||||
|
||||
int gid = strtoul(args[1], &end, 0);
|
||||
if (*end != '\0' || args[1][0] == 0) {
|
||||
ErrorAbort(state, "%s: \"%s\" not a valid gid", name, args[1]);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (recursive) {
|
||||
int dir_mode = strtoul(args[2], &end, 0);
|
||||
if (*end != '\0' || args[2][0] == 0) {
|
||||
ErrorAbort(state, "%s: \"%s\" not a valid dirmode", name, args[2]);
|
||||
goto done;
|
||||
}
|
||||
|
||||
int file_mode = strtoul(args[3], &end, 0);
|
||||
if (*end != '\0' || args[3][0] == 0) {
|
||||
ErrorAbort(state, "%s: \"%s\" not a valid filemode",
|
||||
name, args[3]);
|
||||
goto done;
|
||||
}
|
||||
|
||||
for (i = 4; i < argc; ++i) {
|
||||
dirSetHierarchyPermissions(args[i], uid, gid, dir_mode, file_mode);
|
||||
}
|
||||
} else {
|
||||
int mode = strtoul(args[2], &end, 0);
|
||||
if (*end != '\0' || args[2][0] == 0) {
|
||||
ErrorAbort(state, "%s: \"%s\" not a valid mode", name, args[2]);
|
||||
goto done;
|
||||
}
|
||||
|
||||
for (i = 3; i < argc; ++i) {
|
||||
if (chown(args[i], uid, gid) < 0) {
|
||||
printf("%s: chown of %s to %d %d failed: %s\n",
|
||||
name, args[i], uid, gid, strerror(errno));
|
||||
++bad;
|
||||
}
|
||||
if (chmod(args[i], mode) < 0) {
|
||||
printf("%s: chmod of %s to %o failed: %s\n",
|
||||
name, args[i], mode, strerror(errno));
|
||||
++bad;
|
||||
}
|
||||
}
|
||||
}
|
||||
result = strdup("");
|
||||
|
||||
done:
|
||||
for (i = 0; i < argc; ++i) {
|
||||
free(args[i]);
|
||||
}
|
||||
free(args);
|
||||
|
||||
if (bad) {
|
||||
free(result);
|
||||
return ErrorAbort(state, "%s: some changes failed", name);
|
||||
}
|
||||
return StringValue(result);
|
||||
}
|
||||
|
||||
struct perm_parsed_args {
|
||||
bool has_uid;
|
||||
uid_t uid;
|
||||
|
@ -1398,11 +1316,6 @@ void RegisterInstallFunctions() {
|
|||
RegisterFunction("package_extract_file", PackageExtractFileFn);
|
||||
RegisterFunction("symlink", SymlinkFn);
|
||||
|
||||
// Maybe, at some future point, we can delete these functions? They have been
|
||||
// replaced by perm_set and perm_set_recursive.
|
||||
RegisterFunction("set_perm", SetPermFn);
|
||||
RegisterFunction("set_perm_recursive", SetPermFn);
|
||||
|
||||
// Usage:
|
||||
// set_metadata("filename", "key1", "value1", "key2", "value2", ...)
|
||||
// Example:
|
||||
|
|
Loading…
Reference in a new issue