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:
Jack Bates 2016-11-10 22:24:38 +00:00
Родитель 6da5cd3bb3
Коммит c2c1c10265
5 изменённых файлов: 43 добавлений и 38 удалений

Просмотреть файл

@ -263,13 +263,13 @@ main(int argc, char **argv)
{ {
int onlydir, dodir, dolink, dorelsymlink, dotimes, opt, len, lplen, tdlen, bnlen, exists; int onlydir, dodir, dolink, dorelsymlink, dotimes, opt, len, lplen, tdlen, bnlen, exists;
mode_t mode = 0755; 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; uid_t uid;
gid_t gid; gid_t gid;
struct stat sb, tosb, fromsb; struct stat sb, tosb, fromsb;
program = argv[0]; program = argv[0];
cwd = linkname = linkprefix = owner = group = 0; cwd = linkname = absolute = linkprefix = owner = group = 0;
onlydir = dodir = dolink = dorelsymlink = dotimes = lplen = 0; onlydir = dodir = dolink = dorelsymlink = dotimes = lplen = 0;
while ((opt = getopt(argc, argv, "C:DdlL:Rm:o:g:t")) != EOF) { 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) { if (access(name, R_OK) != 0) {
fail("cannot access %s", name); fail("cannot access %s", name);
} }
if (*name == '/') { if (linkprefix) {
/* source is absolute pathname, link to it directly */ /* -L prefixes names with a $cwd arg. */
linkname = 0; len += lplen + 1;
} else { linkname = xmalloc((unsigned int)(len + 1));
if (linkprefix) { sprintf(linkname, "%s/%s", linkprefix, name);
/* -L prefixes names with a $cwd arg. */ } else if (dorelsymlink) {
len += lplen + 1; if (*name != '/') {
linkname = xmalloc((unsigned int)(len + 1)); absolute = xmalloc((unsigned int)(strlen(cwd) + 1 + len + 1));
sprintf(linkname, "%s/%s", linkprefix, name); sprintf(absolute, "%s/%s", cwd, name);
} else if (dorelsymlink) { name = absolute;
/* Symlink the relative path from todir to source name. */ }
linkname = xmalloc(PATH_MAX);
/* Symlink the relative path from todir to source name. */
if (*todir == '/') { linkname = xmalloc(PATH_MAX);
/* todir is absolute: skip over common prefix. */
lplen = relatepaths(todir, cwd, linkname); /* todir is absolute: skip over common prefix. */
strcpy(linkname + lplen, name); len = relatepaths(todir, name, linkname);
} else { if (len > 0) {
/* todir is named by a relative path: reverse it. */ linkname[--len] = '\0';
reversepath(todir, name, len, linkname); }
xchdir(cwd);
} if (absolute) {
free(absolute);
len = strlen(linkname); absolute = 0;
} }
name = linkname;
} }
name = linkname;
/* Check for a pre-existing symlink with identical content. */ /* Check for a pre-existing symlink with identical content. */
if (exists && (!S_ISLNK(tosb.st_mode) || if (exists && (!S_ISLNK(tosb.st_mode) ||

Просмотреть файл

@ -545,6 +545,7 @@ class JarMaker(object):
if e.errno != errno.ENOENT: if e.errno != errno.ENOENT:
raise raise
if sys.platform != 'win32': if sys.platform != 'win32':
src = os.path.relpath(src, os.path.dirname(out))
os.symlink(src, out) os.symlink(src, out)
else: else:
# On Win32, use ctypes to create a hardlink # 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 # Read the link and check if it is correct
if not os.path.islink(dest): if not os.path.islink(dest):
return False 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) abssrc = os.path.abspath(src)
return target == abssrc return target == abssrc

Просмотреть файл

@ -323,23 +323,25 @@ class AbsoluteSymlinkFile(File):
if ose.errno != errno.ENOENT: if ose.errno != errno.ENOENT:
raise 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 the dest is a symlink pointing to us, we have nothing to do.
# If it's the wrong symlink, the filesystem must support symlinks, # If it's the wrong symlink, the filesystem must support symlinks,
# so we replace with a proper symlink. # so we replace with a proper symlink.
if st and stat.S_ISLNK(st.st_mode): if st and stat.S_ISLNK(st.st_mode):
link = os.readlink(dest) link = os.readlink(dest)
if link == self.path: if link == src:
return False return False
os.remove(dest) os.remove(dest)
os.symlink(self.path, dest) os.symlink(src, dest)
return True return True
# If the destination doesn't exist, we try to create a symlink. If that # If the destination doesn't exist, we try to create a symlink. If that
# fails, we fall back to copy code. # fails, we fall back to copy code.
if not st: if not st:
try: try:
os.symlink(self.path, dest) os.symlink(src, dest)
return True return True
except OSError: except OSError:
return File.copy(self, dest, skip_if_older=skip_if_older) 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())) temp_dest = os.path.join(os.path.dirname(dest), str(uuid.uuid4()))
try: try:
os.symlink(self.path, temp_dest) os.symlink(src, temp_dest)
# TODO Figure out exactly how symlink creation fails and only trap # TODO Figure out exactly how symlink creation fails and only trap
# that. # that.
except EnvironmentError: except EnvironmentError:

Просмотреть файл

@ -283,7 +283,7 @@ class TestAbsoluteSymlinkFile(TestWithTmpDir):
if self.symlink_supported: if self.symlink_supported:
self.assertTrue(os.path.islink(dest)) self.assertTrue(os.path.islink(dest))
link = os.readlink(dest) link = os.readlink(dest)
self.assertEqual(link, source) self.assertEqual(link, 'test_path')
else: else:
self.assertTrue(os.path.isfile(dest)) self.assertTrue(os.path.isfile(dest))
content = open(dest).read() content = open(dest).read()
@ -306,7 +306,7 @@ class TestAbsoluteSymlinkFile(TestWithTmpDir):
if self.symlink_supported: if self.symlink_supported:
self.assertTrue(os.path.islink(dest)) self.assertTrue(os.path.islink(dest))
link = os.readlink(dest) link = os.readlink(dest)
self.assertEqual(link, source) self.assertEqual(link, 'test_path')
else: else:
self.assertTrue(os.path.isfile(dest)) self.assertTrue(os.path.isfile(dest))
content = open(dest).read() content = open(dest).read()
@ -330,7 +330,7 @@ class TestAbsoluteSymlinkFile(TestWithTmpDir):
self.assertTrue(os.path.islink(dest)) self.assertTrue(os.path.islink(dest))
link = os.readlink(dest) link = os.readlink(dest)
self.assertEqual(link, source) self.assertEqual(link, 'source')
def test_noop(self): def test_noop(self):
if not hasattr(os, 'symlink'): if not hasattr(os, 'symlink'):
@ -342,15 +342,15 @@ class TestAbsoluteSymlinkFile(TestWithTmpDir):
with open(source, 'a'): with open(source, 'a'):
pass pass
os.symlink(source, dest) os.symlink('source', dest)
link = os.readlink(dest) link = os.readlink(dest)
self.assertEqual(link, source) self.assertEqual(link, 'source')
s = AbsoluteSymlinkFile(source) s = AbsoluteSymlinkFile(source)
self.assertFalse(s.copy(dest)) self.assertFalse(s.copy(dest))
link = os.readlink(dest) link = os.readlink(dest)
self.assertEqual(link, source) self.assertEqual(link, 'source')
class TestPreprocessedFile(TestWithTmpDir): class TestPreprocessedFile(TestWithTmpDir):
def test_preprocess(self): def test_preprocess(self):