[Toybox] Regarding usage of cp --preserve
Hyejin Kim
hj8296 at gmail.com
Mon Aug 31 19:40:18 PDT 2015
Hi.
When I adding --preserve=context option into cp --preserve, found some
abnormal behavior.
So, try to share with you and want to find right way or modification.
Internally, --preserve uses comma_scan() function on parsing attributes.
But I guess it can't cover the string without last comma.
like, "cp --preserve=timestamps,mode" or "cp --preserve=timestamps"
This will display "bad --preserve=mode" or "bad --preserve=timestamps"
Furthur, I can't understand well the logic parsing first letter of
attributes.
if I execute "cp --preserve=mota", it also goes error.
340 if (CFG_CP_PRESERVE && TT.c.preserve) {
341 char *pre = xstrdup(TT.c.preserve), *s;
342
343 if (comma_scan(pre, "all", 1)) TT.pflags = ~0;
344 else
{
// <-- I just added this for test. and if all string is catched, I think we
do not need to dig more.
345 for (i=0; i<ARRAY_LEN(preserve); i++)
346 if (comma_scan(pre, preserve[i], 1)) TT.pflags |= 1<<i;
347 if (*pre)
{
348
349 // Try to interpret as letters, commas won't set anything this
doesn't.
350 for (s = TT.c.preserve; *s; s++)
{ // <-- if have *pre ( in short
this means remained string without seperating comma), try to compare
character on by on from original input (TT.c.preserve)
// I guess, this code allow the combination of first letter format (like
mota) and full name format(like mode,timestamps), right ?
// For example, "cp --preserve=timestamps,m". this uses both of full name
format and first letter format. I just wonder Rob's intention.
// Which usage is correct and can be supported?
351 printf("*s :%s\n", s);
352 for (i=0; i<ARRAY_LEN(preserve); i++)
353 if (*s == *preserve[i]) TT.pflags |= 1<<i;
354 if (i == ARRAY_LEN(preserve)) {
355 if (*s == 'a') TT.pflags = ~0;
356 else
break;
// this compare one character with each "m/o/t/a". *s it just only the
first letter of user input. if failed to comparing with 'a', breaked. Is it
right?
// How can arrive next character if have a string example "mot". this has
no 'a'. just will be compared by m only then breaked.
7 }
358 }
359
360 if (*s) error_exit("bad --preserve=%s", pre);
361 }
362 }
363 free(pre);
364 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20150901/aa205137/attachment-0002.htm>
More information about the Toybox
mailing list