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:
@@ -135,9 +135,9 @@ writeAttr(int fd, type_code type, const char *name, const char *value, size_t le
|
|||||||
|
|
||||||
status_t
|
status_t
|
||||||
addAttr(const char *file, type_code type, const char *name,
|
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)
|
if (fd < 0)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,6 @@
|
|||||||
|
|
||||||
|
|
||||||
status_t addAttr(const char *file, type_code attrType, const char *attrName,
|
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 */
|
#endif /* _ADD_ATTR_H */
|
||||||
|
|||||||
@@ -86,8 +86,9 @@ typeForString(const char *string, type_code *_result)
|
|||||||
void
|
void
|
||||||
usage(int returnValue)
|
usage(int returnValue)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: %s [-t type] attr value file1 [file2...]\n"
|
fprintf(stderr, "usage: %s [-t type] [ -P ] attr value file1 [file2...]\n"
|
||||||
" or: %s [-f value-from-file] [-t type] attr file1 [file2...]\n\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"
|
"\tType is one of:\n"
|
||||||
"\t\tstring, mime, int, llong, float, double, bool, raw\n"
|
"\t\tstring, mime, int, llong, float, double, bool, raw\n"
|
||||||
"\t\tor a numeric value (ie. 0x1234, 42, 'ABCD', ...)\n"
|
"\t\tor a numeric value (ie. 0x1234, 42, 'ABCD', ...)\n"
|
||||||
@@ -148,6 +149,7 @@ main(int argc, char *argv[])
|
|||||||
char *attrValue = NULL;
|
char *attrValue = NULL;
|
||||||
size_t valueFileLength = 0;
|
size_t valueFileLength = 0;
|
||||||
int32 i = 1;
|
int32 i = 1;
|
||||||
|
bool resolveLinks = true;
|
||||||
|
|
||||||
if (!strcmp(argv[i], "-f")) {
|
if (!strcmp(argv[i], "-f")) {
|
||||||
// retrieve attribute value from file
|
// retrieve attribute value from file
|
||||||
@@ -204,6 +206,12 @@ main(int argc, char *argv[])
|
|||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assertArgument(i, argc);
|
||||||
|
if (!strcmp(argv[i], "-P")) {
|
||||||
|
resolveLinks = false;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
assertArgument(i, argc);
|
assertArgument(i, argc);
|
||||||
const char *attrName = argv[i++];
|
const char *attrName = argv[i++];
|
||||||
|
|
||||||
@@ -221,7 +229,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
for (; i < argc; i++) {
|
for (; i < argc; i++) {
|
||||||
status_t status = addAttr(argv[i], attrType, attrName, attrValue,
|
status_t status = addAttr(argv[i], attrType, attrName, attrValue,
|
||||||
valueFileLength);
|
valueFileLength, resolveLinks);
|
||||||
|
|
||||||
// special case for bool types
|
// special case for bool types
|
||||||
if (status == B_BAD_VALUE && attrType == B_BOOL_TYPE)
|
if (status == B_BAD_VALUE && attrType == B_BOOL_TYPE)
|
||||||
|
|||||||
Reference in New Issue
Block a user