mirror of
git://git.9front.org/plan9front/plan9front
synced 2025-01-12 11:10:06 +00:00
libdisk: cleanname() paths for setname()/mkpath(), avoid utfrrune()
This commit is contained in:
parent
9d552b68e4
commit
ddaadd65b4
1 changed files with 14 additions and 17 deletions
|
@ -229,8 +229,8 @@ enum {
|
||||||
static void
|
static void
|
||||||
setname(Mkaux *mkaux, Name *name, File *f)
|
setname(Mkaux *mkaux, Name *name, File *f)
|
||||||
{
|
{
|
||||||
char *s1, *s2, *ss;
|
char *s1, *s2;
|
||||||
int l;
|
int n;
|
||||||
|
|
||||||
s1 = mkaux->root;
|
s1 = mkaux->root;
|
||||||
s2 = "";
|
s2 = "";
|
||||||
|
@ -242,18 +242,14 @@ setname(Mkaux *mkaux, Name *name, File *f)
|
||||||
s2 = f->old;
|
s2 = f->old;
|
||||||
}else
|
}else
|
||||||
s2 = f->new;
|
s2 = f->new;
|
||||||
|
n = strlen(s1) + strlen(s2) + 2;
|
||||||
l = strlen(s1);
|
if(name->n < n+SLOP/2) {
|
||||||
ss = (*s1 && *s2 && *s2 != '/' && s1[l-1] != '/') ? "/" : "";
|
|
||||||
l += strlen(ss);
|
|
||||||
l += strlen(s2);
|
|
||||||
l++;
|
|
||||||
if(name->n < l+SLOP/2) {
|
|
||||||
free(name->s);
|
free(name->s);
|
||||||
name->s = emalloc(mkaux, l+SLOP);
|
name->s = emalloc(mkaux, n+SLOP);
|
||||||
name->n = l+SLOP;
|
name->n = n+SLOP;
|
||||||
}
|
}
|
||||||
snprint(name->s, name->n, "%s%s%s", s1, ss, s2);
|
snprint(name->s, name->n, "%s/%s", s1, s2);
|
||||||
|
cleanname(name->s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -311,10 +307,8 @@ mkpath(Mkaux *mkaux, char *prefix, char *elem)
|
||||||
|
|
||||||
n = strlen(prefix) + strlen(elem) + 2;
|
n = strlen(prefix) + strlen(elem) + 2;
|
||||||
p = emalloc(mkaux, n);
|
p = emalloc(mkaux, n);
|
||||||
strcpy(p, prefix);
|
snprint(p, n, "%s/%s", prefix, elem);
|
||||||
strcat(p, "/");
|
return cleanname(p);
|
||||||
strcat(p, elem);
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -552,8 +546,11 @@ loop:
|
||||||
|
|
||||||
f = emalloc(mkaux, sizeof *f);
|
f = emalloc(mkaux, sizeof *f);
|
||||||
f->new = mkpath(mkaux, old->new, elem);
|
f->new = mkpath(mkaux, old->new, elem);
|
||||||
|
if((s = strrchr(f->new, '/')) != nil)
|
||||||
|
f->elem = s+1;
|
||||||
|
else
|
||||||
|
f->elem = f->new;
|
||||||
free(elem);
|
free(elem);
|
||||||
f->elem = utfrrune(f->new, L'/') + 1;
|
|
||||||
|
|
||||||
if((p = getmode(mkaux, p, &f->mode)) == nil){
|
if((p = getmode(mkaux, p, &f->mode)) == nil){
|
||||||
freefile(f);
|
freefile(f);
|
||||||
|
|
Loading…
Reference in a new issue