Gentoo Archives: gentoo-catalyst

From: Brian Dolbec <dolsen@g.o>
To: gentoo-catalyst@l.g.o
Cc: Brian Dolbec <dolsen@g.o>
Subject: [gentoo-catalyst] [PATCH] Remove some troublesome trailing slashes from paths
Date: Sat, 11 Jan 2014 19:47:11
Message-Id: 1389469387-29010-2-git-send-email-dolsen@gentoo.org
In Reply to: [gentoo-catalyst] Start bringing consistent format to paths by Brian Dolbec
1 Change the docstring to warn to use a proper path join function.
2 Fix a relative path bug after removing the above slash
3 by moving the "."
4 ---
5 modules/generic_stage_target.py | 28 +++++++++++++++-------------
6 modules/livecd_stage2_target.py | 4 +++-
7 modules/stage2_target.py | 8 ++++++--
8 targets/support/functions.sh | 4 ++--
9 4 files changed, 26 insertions(+), 18 deletions(-)
10
11 diff --git a/modules/generic_stage_target.py b/modules/generic_stage_target.py
12 index 3d66231..a5b52b0 100644
13 --- a/modules/generic_stage_target.py
14 +++ b/modules/generic_stage_target.py
15 @@ -331,8 +331,9 @@ class generic_stage_target(generic_target):
16 "/kerncache/"+self.settings["target_subpath"]+"/")
17
18 def set_target_path(self):
19 - self.settings["target_path"]=normpath(self.settings["storedir"]+\
20 - "/builds/"+self.settings["target_subpath"]+".tar.bz2")
21 + self.settings["target_path"] = normpath(self.settings["storedir"] +
22 + "/builds/" + self.settings["target_subpath"].rstrip('/') +
23 + ".tar.bz2")
24 if "AUTORESUME" in self.settings\
25 and os.path.exists(self.settings["autoresume_path"]+\
26 "setup_target_path"):
27 @@ -417,8 +418,9 @@ class generic_stage_target(generic_target):
28 self.settings["source_path"]=normpath(self.settings["storedir"]+\
29 "/tmp/"+self.settings["source_subpath"]+"/")
30 else:
31 - self.settings["source_path"]=normpath(self.settings["storedir"]+\
32 - "/builds/"+self.settings["source_subpath"]+".tar.bz2")
33 + self.settings["source_path"] = normpath(self.settings["storedir"] +
34 + "/builds/" + self.settings["source_subpath"].rstrip("/") +
35 + ".tar.bz2")
36 if os.path.isfile(self.settings["source_path"]):
37 # XXX: Is this even necessary if the previous check passes?
38 if os.path.exists(self.settings["source_path"]):
39 @@ -431,8 +433,8 @@ class generic_stage_target(generic_target):
40 print "\tIf this is not desired, remove this directory or turn off"
41 print "\tseedcache in the options of catalyst.conf the source path"
42 print "\twill then be "+\
43 - normpath(self.settings["storedir"]+"/builds/"+\
44 - self.settings["source_subpath"]+".tar.bz2\n")
45 + normpath(self.settings["storedir"] + "/builds/" +
46 + self.settings["source_subpath"].rstrip("/") + ".tar.bz2\n")
47
48 def set_dest_path(self):
49 if "root_path" in self.settings:
50 @@ -446,9 +448,9 @@ class generic_stage_target(generic_target):
51 "/root/*", self.settings["portdir"]]
52
53 def set_snapshot_path(self):
54 - self.settings["snapshot_path"]=normpath(self.settings["storedir"]+\
55 + self.settings["snapshot_path"] = normpath(self.settings["storedir"] +
56 "/snapshots/" + self.settings["snapshot_name"] +
57 - self.settings["snapshot"] + ".tar.xz")
58 + self.settings["snapshot"].rstrip("/") + ".tar.xz")
59
60 if os.path.exists(self.settings["snapshot_path"]):
61 self.settings["snapshot_path_hash"]=\
62 @@ -457,7 +459,7 @@ class generic_stage_target(generic_target):
63 else:
64 self.settings["snapshot_path"]=normpath(self.settings["storedir"]+\
65 "/snapshots/" + self.settings["snapshot_name"] +
66 - self.settings["snapshot"] + ".tar.bz2")
67 + self.settings["snapshot"].rstrip("/") + ".tar.bz2")
68
69 if os.path.exists(self.settings["snapshot_path"]):
70 self.settings["snapshot_path_hash"]=\
71 @@ -468,18 +470,18 @@ class generic_stage_target(generic_target):
72 if "SNAPCACHE" in self.settings:
73 self.settings["snapshot_cache_path"]=\
74 normpath(self.settings["snapshot_cache"]+"/"+\
75 - self.settings["snapshot"]+"/")
76 + self.settings["snapshot"])
77 self.snapcache_lock=\
78 catalyst_lock.LockDir(self.settings["snapshot_cache_path"])
79 print "Caching snapshot to "+self.settings["snapshot_cache_path"]
80
81 def set_chroot_path(self):
82 """
83 - NOTE: the trailing slash is very important!
84 - Things *will* break without it!
85 + NOTE: the trailing slash has been removed
86 + Things *could* break if you don't use a proper join()
87 """
88 self.settings["chroot_path"]=normpath(self.settings["storedir"]+\
89 - "/tmp/"+self.settings["target_subpath"]+"/")
90 + "/tmp/"+self.settings["target_subpath"])
91 self.chroot_lock=catalyst_lock.LockDir(self.settings["chroot_path"])
92
93 def set_autoresume_path(self):
94 diff --git a/modules/livecd_stage2_target.py b/modules/livecd_stage2_target.py
95 index 5be8fd2..c74c16d 100644
96 --- a/modules/livecd_stage2_target.py
97 +++ b/modules/livecd_stage2_target.py
98 @@ -33,7 +33,9 @@ class livecd_stage2_target(generic_stage_target):
99 file_locate(self.settings, ["cdtar","controller_file"])
100
101 def set_source_path(self):
102 - self.settings["source_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2")
103 + self.settings["source_path"] = normpath(self.settings["storedir"] +
104 + "/builds/" + self.settings["source_subpath"].rstrip("/") +
105 + ".tar.bz2")
106 if os.path.isfile(self.settings["source_path"]):
107 self.settings["source_path_hash"]=generate_hash(self.settings["source_path"])
108 else:
109 diff --git a/modules/stage2_target.py b/modules/stage2_target.py
110 index 6083e2b..803ec59 100644
111 --- a/modules/stage2_target.py
112 +++ b/modules/stage2_target.py
113 @@ -19,7 +19,9 @@ class stage2_target(generic_stage_target):
114 if "SEEDCACHE" in self.settings and os.path.isdir(normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/tmp/stage1root/")):
115 self.settings["source_path"]=normpath(self.settings["storedir"]+"/tmp/"+self.settings["source_subpath"]+"/tmp/stage1root/")
116 else:
117 - self.settings["source_path"]=normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2")
118 + self.settings["source_path"] = normpath(self.settings["storedir"] +
119 + "/builds/" + self.settings["source_subpath"].rstrip("/") +
120 + ".tar.bz2")
121 if os.path.isfile(self.settings["source_path"]):
122 if os.path.exists(self.settings["source_path"]):
123 # XXX: Is this even necessary if the previous check passes?
124 @@ -28,7 +30,9 @@ class stage2_target(generic_stage_target):
125 print "Source path set to "+self.settings["source_path"]
126 if os.path.isdir(self.settings["source_path"]):
127 print "\tIf this is not desired, remove this directory or turn of seedcache in the options of catalyst.conf"
128 - print "\tthe source path will then be "+normpath(self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2\n")
129 + print "\tthe source path will then be " + \
130 + normpath(self.settings["storedir"] + "/builds/" + \
131 + self.settings["source_subpath"].restrip("/") + ".tar.bz2\n")
132
133 # XXX: How do these override_foo() functions differ from the ones in
134 # generic_stage_target and why aren't they in stage3_target?
135 diff --git a/targets/support/functions.sh b/targets/support/functions.sh
136 index 80e371c..3245862 100755
137 --- a/targets/support/functions.sh
138 +++ b/targets/support/functions.sh
139 @@ -20,7 +20,7 @@ exec_in_chroot(){
140 # and executes it.
141 local file_name=$(basename ${1})
142 local subdir=${2}
143 - local destdir=".${subdir}/tmp"
144 + local destdir="${subdir}/tmp"
145
146 echo "Copying ${file_name} to ${destdir}"
147 copy_to_chroot ${1} ${destdir}
148 @@ -33,7 +33,7 @@ exec_in_chroot(){
149 chmod +x ${chroot_path}/${destdir}/${file_name}
150
151 echo "Running ${file_name} in chroot ${chroot_path}"
152 - ${clst_CHROOT} ${chroot_path} ${destdir}/${file_name} || exit 1
153 + ${clst_CHROOT} ${chroot_path} .${destdir}/${file_name} || exit 1
154
155 delete_from_chroot ${destdir}/${file_name}
156 delete_from_chroot ${destdir}/chroot-functions.sh
157 --
158 1.8.3.2

Replies

Subject Author
[gentoo-catalyst] Re: [PATCH] Remove some troublesome trailing slashes from paths "W. Trevor King" <wking@×××××××.us>