diff options
author | Enrico Scholz <enrico.scholz@sigma-chemnitz.de> | 2013-02-10 13:41:46 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-02-11 14:46:11 +0000 |
commit | 21b6ff9bc36f5706456b3ed3ca7b6455f77a5eaa (patch) | |
tree | a81edd12c3629331741ce3caf10d931531989ccb /meta/lib/oe/tests | |
parent | f2e16c655286aab465054db6727fa3365bef3124 (diff) | |
download | poky-21b6ff9bc36f5706456b3ed3ca7b6455f77a5eaa.tar.gz |
lib: implemented oe.path.realpath()
Various parts of the buildsystem have to work with symlinks. Resolving
them is not trivial because they are always relative to a sysroot
directory.
Patch adds a function which returns the destination of a symlink by
assuming a given path as the / toplevel directory. A testsuite was
added too.
(From OE-Core rev: 76e0bd7f8e3a3bd052a6e329f88e2d8099e899c4)
Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe/tests')
-rw-r--r-- | meta/lib/oe/tests/test_path.py | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/meta/lib/oe/tests/test_path.py b/meta/lib/oe/tests/test_path.py new file mode 100644 index 0000000000..e6aa601618 --- /dev/null +++ b/meta/lib/oe/tests/test_path.py | |||
@@ -0,0 +1,89 @@ | |||
1 | import unittest | ||
2 | import oe, oe.path | ||
3 | import tempfile | ||
4 | import os | ||
5 | import errno | ||
6 | import shutil | ||
7 | |||
8 | class TestRealPath(unittest.TestCase): | ||
9 | DIRS = [ "a", "b", "etc", "sbin", "usr", "usr/bin", "usr/binX", "usr/sbin", "usr/include", "usr/include/gdbm" ] | ||
10 | FILES = [ "etc/passwd", "b/file" ] | ||
11 | LINKS = [ | ||
12 | ( "bin", "/usr/bin", "/usr/bin" ), | ||
13 | ( "binX", "usr/binX", "/usr/binX" ), | ||
14 | ( "c", "broken", "/broken" ), | ||
15 | ( "etc/passwd-1", "passwd", "/etc/passwd" ), | ||
16 | ( "etc/passwd-2", "passwd-1", "/etc/passwd" ), | ||
17 | ( "etc/passwd-3", "/etc/passwd-1", "/etc/passwd" ), | ||
18 | ( "etc/shadow-1", "/etc/shadow", "/etc/shadow" ), | ||
19 | ( "etc/shadow-2", "/etc/shadow-1", "/etc/shadow" ), | ||
20 | ( "prog-A", "bin/prog-A", "/usr/bin/prog-A" ), | ||
21 | ( "prog-B", "/bin/prog-B", "/usr/bin/prog-B" ), | ||
22 | ( "usr/bin/prog-C", "../../sbin/prog-C", "/sbin/prog-C" ), | ||
23 | ( "usr/bin/prog-D", "/sbin/prog-D", "/sbin/prog-D" ), | ||
24 | ( "usr/binX/prog-E", "../sbin/prog-E", None ), | ||
25 | ( "usr/bin/prog-F", "../../../sbin/prog-F", "/sbin/prog-F" ), | ||
26 | ( "loop", "a/loop", None ), | ||
27 | ( "a/loop", "../loop", None ), | ||
28 | ( "b/test", "file/foo", None ), | ||
29 | ] | ||
30 | |||
31 | LINKS_PHYS = [ | ||
32 | ( "./", "/", "" ), | ||
33 | ( "binX/prog-E", "/usr/sbin/prog-E", "/sbin/prog-E" ), | ||
34 | ] | ||
35 | |||
36 | EXCEPTIONS = [ | ||
37 | ( "loop", errno.ELOOP ), | ||
38 | ( "b/test", errno.ENOENT ), | ||
39 | ] | ||
40 | |||
41 | def __del__(self): | ||
42 | try: | ||
43 | #os.system("tree -F %s" % self.tmpdir) | ||
44 | shutil.rmtree(self.tmpdir) | ||
45 | except: | ||
46 | pass | ||
47 | |||
48 | def setUp(self): | ||
49 | self.tmpdir = tempfile.mkdtemp(prefix = "oe-test_path") | ||
50 | self.root = os.path.join(self.tmpdir, "R") | ||
51 | |||
52 | os.mkdir(os.path.join(self.tmpdir, "_real")) | ||
53 | os.symlink("_real", self.root) | ||
54 | |||
55 | for d in self.DIRS: | ||
56 | os.mkdir(os.path.join(self.root, d)) | ||
57 | for f in self.FILES: | ||
58 | file(os.path.join(self.root, f), "w") | ||
59 | for l in self.LINKS: | ||
60 | os.symlink(l[1], os.path.join(self.root, l[0])) | ||
61 | |||
62 | def __realpath(self, file, use_physdir): | ||
63 | return oe.path.realpath(os.path.join(self.root, file), self.root, use_physdir) | ||
64 | |||
65 | def test_norm(self): | ||
66 | for l in self.LINKS: | ||
67 | if l[2] == None: | ||
68 | continue | ||
69 | |||
70 | target_p = self.__realpath(l[0], True) | ||
71 | target_l = self.__realpath(l[0], False) | ||
72 | |||
73 | if l[2] != False: | ||
74 | self.assertEqual(target_p, target_l) | ||
75 | self.assertEqual(l[2], target_p[len(self.root):]) | ||
76 | |||
77 | def test_phys(self): | ||
78 | for l in self.LINKS_PHYS: | ||
79 | target_p = self.__realpath(l[0], True) | ||
80 | target_l = self.__realpath(l[0], False) | ||
81 | |||
82 | self.assertEqual(l[1], target_p[len(self.root):]) | ||
83 | self.assertEqual(l[2], target_l[len(self.root):]) | ||
84 | |||
85 | def test_loop(self): | ||
86 | for e in self.EXCEPTIONS: | ||
87 | self.assertRaisesRegexp(OSError, r'\[Errno %u\]' % e[1], | ||
88 | self.__realpath, e[0], False) | ||
89 | |||