From 8b20dbc8a77c04cb973b6bc853ed4cb76f2e5fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sat, 30 May 2009 14:12:00 +0000 Subject: [PATCH] addattr can now add attributes to directories and symlinks git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30923 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/bin/addattr/addAttr.cpp | 4 ++-- src/bin/addattr/addAttr.h | 2 +- src/bin/addattr/main.cpp | 14 +++++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/bin/addattr/addAttr.cpp b/src/bin/addattr/addAttr.cpp index d46f451408..257e490f90 100644 --- a/src/bin/addattr/addAttr.cpp +++ b/src/bin/addattr/addAttr.cpp @@ -135,9 +135,9 @@ writeAttr(int fd, type_code type, const char *name, const char *value, size_t le status_t addAttr(const char *file, type_code type, const char *name, - const char *value, size_t length) + const char *value, size_t length, bool resolveLinks) { - int fd = open(file, O_WRONLY); + int fd = open(file, O_RDONLY | (resolveLinks ? 0 : O_NOTRAVERSE)); if (fd < 0) return errno; diff --git a/src/bin/addattr/addAttr.h b/src/bin/addattr/addAttr.h index e1403ada50..1190b017c9 100644 --- a/src/bin/addattr/addAttr.h +++ b/src/bin/addattr/addAttr.h @@ -12,6 +12,6 @@ status_t addAttr(const char *file, type_code attrType, const char *attrName, - const char *attrValue, size_t length); + const char *attrValue, size_t length, bool resolveLinks); #endif /* _ADD_ATTR_H */ diff --git a/src/bin/addattr/main.cpp b/src/bin/addattr/main.cpp index c9029e7942..2059cbd3dc 100644 --- a/src/bin/addattr/main.cpp +++ b/src/bin/addattr/main.cpp @@ -86,8 +86,9 @@ typeForString(const char *string, type_code *_result) void usage(int returnValue) { - fprintf(stderr, "usage: %s [-t type] attr value file1 [file2...]\n" - " or: %s [-f value-from-file] [-t type] attr file1 [file2...]\n\n" + fprintf(stderr, "usage: %s [-t type] [ -P ] attr value file1 [file2...]\n" + " or: %s [-f value-from-file] [-t type] [ -P ] attr file1 [file2...]\n\n" + "\t-P : Don't resolve links\n" "\tType is one of:\n" "\t\tstring, mime, int, llong, float, double, bool, raw\n" "\t\tor a numeric value (ie. 0x1234, 42, 'ABCD', ...)\n" @@ -148,6 +149,7 @@ main(int argc, char *argv[]) char *attrValue = NULL; size_t valueFileLength = 0; int32 i = 1; + bool resolveLinks = true; if (!strcmp(argv[i], "-f")) { // retrieve attribute value from file @@ -204,6 +206,12 @@ main(int argc, char *argv[]) i += 2; } + assertArgument(i, argc); + if (!strcmp(argv[i], "-P")) { + resolveLinks = false; + i++; + } + assertArgument(i, argc); const char *attrName = argv[i++]; @@ -221,7 +229,7 @@ main(int argc, char *argv[]) for (; i < argc; i++) { status_t status = addAttr(argv[i], attrType, attrName, attrValue, - valueFileLength); + valueFileLength, resolveLinks); // special case for bool types if (status == B_BAD_VALUE && attrType == B_BOOL_TYPE)