Skip to content

Commit b1ea72c

Browse files
authored
Merge pull request #60 from tlindner/copy-attr
os9 copy: add option to set file attributes during copy
2 parents bbfc5db + 94c8e00 commit b1ea72c

1 file changed

Lines changed: 98 additions & 0 deletions

File tree

os9/os9copy.c

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static char const *const helpMessage[] = {
2828
" -b=size size of copy buffer in bytes or K-bytes\n",
2929
" -l perform end of line translation\n",
3030
" -o=id set file's owner as id\n",
31+
" -a=attrs set file attributes (same syntax as attr)\n",
3132
" -r rewrite if file exists\n",
3233
NULL
3334
};
@@ -45,6 +46,9 @@ int os9copy(int argc, char *argv[])
4546
char df[256];
4647
int owner = 0, owner_set = 0;
4748
char *buffer;
49+
int attrSetMask = 0;
50+
int attrResetMask = 0;
51+
int attr_set = 0;
4852
u_int buffer_size = 32768;
4953

5054

@@ -99,6 +103,82 @@ int os9copy(int argc, char *argv[])
99103
p = q;
100104
break;
101105

106+
case 'a':
107+
if (*(++p) == '=')
108+
p++;
109+
110+
attr_set = 1;
111+
112+
while (*p != '\0')
113+
{
114+
switch (*p)
115+
{
116+
case 'e':
117+
attrSetMask |= FAP_EXEC;
118+
break;
119+
case 'w':
120+
attrSetMask |= FAP_WRITE;
121+
break;
122+
case 'r':
123+
attrSetMask |= FAP_READ;
124+
break;
125+
case 's':
126+
attrSetMask |= FAP_SINGLE;
127+
break;
128+
case 'p':
129+
switch (*(++p))
130+
{
131+
case 'e':
132+
attrSetMask |= FAP_PEXEC;
133+
break;
134+
case 'w':
135+
attrSetMask |= FAP_PWRITE;
136+
break;
137+
case 'r':
138+
attrSetMask |= FAP_PREAD;
139+
break;
140+
}
141+
break;
142+
case 'n':
143+
switch (*(++p))
144+
{
145+
case 'p':
146+
switch (*(++p))
147+
{
148+
case 'e':
149+
attrResetMask |= FAP_PEXEC;
150+
break;
151+
case 'w':
152+
attrResetMask |= FAP_PWRITE;
153+
break;
154+
case 'r':
155+
attrResetMask |= FAP_PREAD;
156+
break;
157+
}
158+
break;
159+
case 'e':
160+
attrResetMask |= FAP_EXEC;
161+
break;
162+
case 'w':
163+
attrResetMask |= FAP_WRITE;
164+
break;
165+
case 'r':
166+
attrResetMask |= FAP_READ;
167+
break;
168+
case 's':
169+
attrResetMask |= FAP_SINGLE;
170+
break;
171+
case 'd':
172+
attrResetMask |= FAP_DIR;
173+
break;
174+
}
175+
break;
176+
}
177+
p++;
178+
}
179+
p--;
180+
break;
181+
102182
case 'h':
103183
case '?':
104184
show_help(helpMessage);
@@ -284,6 +364,24 @@ int os9copy(int argc, char *argv[])
284364
ec = TSCopyFile(argv[j], df, eolTranslate, rewrite, owner,
285365
owner_set, buffer, buffer_size);
286366

367+
if (ec == 0 && attr_set)
368+
{
369+
char attr;
370+
char attrs[9];
371+
error_code ec2;
372+
373+
ec2 = TSRBFAttrSet(df,
374+
attrSetMask,
375+
attrResetMask,
376+
&attr,
377+
attrs);
378+
379+
if (ec2 != 0)
380+
fprintf(stderr,
381+
"%s: warning: copied '%s' but could not set attributes: %s\n",
382+
argv[0], df, TSReportError(ec2));
383+
}
384+
287385
if (ec != 0)
288386
{
289387
fprintf(stderr,

0 commit comments

Comments
 (0)