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
This commit is contained in:
Jérôme Duval 2009-05-30 14:12:00 +00:00
parent 9738f996e3
commit 8b20dbc8a7
3 changed files with 14 additions and 6 deletions

View File

@ -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;

View File

@ -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 */

View File

@ -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)