зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1316735 - Relative symlinks in the dist directory. r=gps
Make the symlinks in the dist directory relative instead of absolute. MozReview-Commit-ID: HS7KL4JwSbV --HG-- extra : rebase_source : 5dca673cc17423d47e6707d8800f7ee9693a9c48
This commit is contained in:
Родитель
6da5cd3bb3
Коммит
c2c1c10265
|
@ -263,13 +263,13 @@ main(int argc, char **argv)
|
|||
{
|
||||
int onlydir, dodir, dolink, dorelsymlink, dotimes, opt, len, lplen, tdlen, bnlen, exists;
|
||||
mode_t mode = 0755;
|
||||
char *linkprefix, *owner, *group, *cp, *cwd, *todir, *toname, *name, *base, *linkname, buf[BUFSIZ];
|
||||
char *linkprefix, *owner, *group, *cp, *cwd, *todir, *toname, *name, *base, *linkname, *absolute, buf[BUFSIZ];
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
struct stat sb, tosb, fromsb;
|
||||
|
||||
program = argv[0];
|
||||
cwd = linkname = linkprefix = owner = group = 0;
|
||||
cwd = linkname = absolute = linkprefix = owner = group = 0;
|
||||
onlydir = dodir = dolink = dorelsymlink = dotimes = lplen = 0;
|
||||
|
||||
while ((opt = getopt(argc, argv, "C:DdlL:Rm:o:g:t")) != EOF) {
|
||||
|
@ -379,33 +379,33 @@ main(int argc, char **argv)
|
|||
if (access(name, R_OK) != 0) {
|
||||
fail("cannot access %s", name);
|
||||
}
|
||||
if (*name == '/') {
|
||||
/* source is absolute pathname, link to it directly */
|
||||
linkname = 0;
|
||||
} else {
|
||||
if (linkprefix) {
|
||||
/* -L prefixes names with a $cwd arg. */
|
||||
len += lplen + 1;
|
||||
linkname = xmalloc((unsigned int)(len + 1));
|
||||
sprintf(linkname, "%s/%s", linkprefix, name);
|
||||
} else if (dorelsymlink) {
|
||||
/* Symlink the relative path from todir to source name. */
|
||||
linkname = xmalloc(PATH_MAX);
|
||||
|
||||
if (*todir == '/') {
|
||||
/* todir is absolute: skip over common prefix. */
|
||||
lplen = relatepaths(todir, cwd, linkname);
|
||||
strcpy(linkname + lplen, name);
|
||||
} else {
|
||||
/* todir is named by a relative path: reverse it. */
|
||||
reversepath(todir, name, len, linkname);
|
||||
xchdir(cwd);
|
||||
}
|
||||
|
||||
len = strlen(linkname);
|
||||
if (linkprefix) {
|
||||
/* -L prefixes names with a $cwd arg. */
|
||||
len += lplen + 1;
|
||||
linkname = xmalloc((unsigned int)(len + 1));
|
||||
sprintf(linkname, "%s/%s", linkprefix, name);
|
||||
} else if (dorelsymlink) {
|
||||
if (*name != '/') {
|
||||
absolute = xmalloc((unsigned int)(strlen(cwd) + 1 + len + 1));
|
||||
sprintf(absolute, "%s/%s", cwd, name);
|
||||
name = absolute;
|
||||
}
|
||||
|
||||
/* Symlink the relative path from todir to source name. */
|
||||
linkname = xmalloc(PATH_MAX);
|
||||
|
||||
/* todir is absolute: skip over common prefix. */
|
||||
len = relatepaths(todir, name, linkname);
|
||||
if (len > 0) {
|
||||
linkname[--len] = '\0';
|
||||
}
|
||||
|
||||
if (absolute) {
|
||||
free(absolute);
|
||||
absolute = 0;
|
||||
}
|
||||
name = linkname;
|
||||
}
|
||||
name = linkname;
|
||||
|
||||
/* Check for a pre-existing symlink with identical content. */
|
||||
if (exists && (!S_ISLNK(tosb.st_mode) ||
|
||||
|
|
|
@ -545,6 +545,7 @@ class JarMaker(object):
|
|||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
if sys.platform != 'win32':
|
||||
src = os.path.relpath(src, os.path.dirname(out))
|
||||
os.symlink(src, out)
|
||||
else:
|
||||
# On Win32, use ctypes to create a hardlink
|
||||
|
|
|
@ -109,7 +109,9 @@ def is_symlink_to(dest, src):
|
|||
# Read the link and check if it is correct
|
||||
if not os.path.islink(dest):
|
||||
return False
|
||||
target = os.path.abspath(os.readlink(dest))
|
||||
target = os.readlink(dest)
|
||||
target = os.path.join(os.path.dirname(dest), target)
|
||||
target = os.path.abspath(target)
|
||||
abssrc = os.path.abspath(src)
|
||||
return target == abssrc
|
||||
|
||||
|
|
|
@ -323,23 +323,25 @@ class AbsoluteSymlinkFile(File):
|
|||
if ose.errno != errno.ENOENT:
|
||||
raise
|
||||
|
||||
src = os.path.relpath(self.path, os.path.dirname(dest))
|
||||
|
||||
# If the dest is a symlink pointing to us, we have nothing to do.
|
||||
# If it's the wrong symlink, the filesystem must support symlinks,
|
||||
# so we replace with a proper symlink.
|
||||
if st and stat.S_ISLNK(st.st_mode):
|
||||
link = os.readlink(dest)
|
||||
if link == self.path:
|
||||
if link == src:
|
||||
return False
|
||||
|
||||
os.remove(dest)
|
||||
os.symlink(self.path, dest)
|
||||
os.symlink(src, dest)
|
||||
return True
|
||||
|
||||
# If the destination doesn't exist, we try to create a symlink. If that
|
||||
# fails, we fall back to copy code.
|
||||
if not st:
|
||||
try:
|
||||
os.symlink(self.path, dest)
|
||||
os.symlink(src, dest)
|
||||
return True
|
||||
except OSError:
|
||||
return File.copy(self, dest, skip_if_older=skip_if_older)
|
||||
|
@ -362,7 +364,7 @@ class AbsoluteSymlinkFile(File):
|
|||
|
||||
temp_dest = os.path.join(os.path.dirname(dest), str(uuid.uuid4()))
|
||||
try:
|
||||
os.symlink(self.path, temp_dest)
|
||||
os.symlink(src, temp_dest)
|
||||
# TODO Figure out exactly how symlink creation fails and only trap
|
||||
# that.
|
||||
except EnvironmentError:
|
||||
|
|
|
@ -283,7 +283,7 @@ class TestAbsoluteSymlinkFile(TestWithTmpDir):
|
|||
if self.symlink_supported:
|
||||
self.assertTrue(os.path.islink(dest))
|
||||
link = os.readlink(dest)
|
||||
self.assertEqual(link, source)
|
||||
self.assertEqual(link, 'test_path')
|
||||
else:
|
||||
self.assertTrue(os.path.isfile(dest))
|
||||
content = open(dest).read()
|
||||
|
@ -306,7 +306,7 @@ class TestAbsoluteSymlinkFile(TestWithTmpDir):
|
|||
if self.symlink_supported:
|
||||
self.assertTrue(os.path.islink(dest))
|
||||
link = os.readlink(dest)
|
||||
self.assertEqual(link, source)
|
||||
self.assertEqual(link, 'test_path')
|
||||
else:
|
||||
self.assertTrue(os.path.isfile(dest))
|
||||
content = open(dest).read()
|
||||
|
@ -330,7 +330,7 @@ class TestAbsoluteSymlinkFile(TestWithTmpDir):
|
|||
|
||||
self.assertTrue(os.path.islink(dest))
|
||||
link = os.readlink(dest)
|
||||
self.assertEqual(link, source)
|
||||
self.assertEqual(link, 'source')
|
||||
|
||||
def test_noop(self):
|
||||
if not hasattr(os, 'symlink'):
|
||||
|
@ -342,15 +342,15 @@ class TestAbsoluteSymlinkFile(TestWithTmpDir):
|
|||
with open(source, 'a'):
|
||||
pass
|
||||
|
||||
os.symlink(source, dest)
|
||||
os.symlink('source', dest)
|
||||
link = os.readlink(dest)
|
||||
self.assertEqual(link, source)
|
||||
self.assertEqual(link, 'source')
|
||||
|
||||
s = AbsoluteSymlinkFile(source)
|
||||
self.assertFalse(s.copy(dest))
|
||||
|
||||
link = os.readlink(dest)
|
||||
self.assertEqual(link, source)
|
||||
self.assertEqual(link, 'source')
|
||||
|
||||
class TestPreprocessedFile(TestWithTmpDir):
|
||||
def test_preprocess(self):
|
||||
|
|
Загрузка…
Ссылка в новой задаче