Class: Bundler::FileUtils::Entry_
- Inherits:
-
Object
- Object
- Bundler::FileUtils::Entry_
- Includes:
- StreamUtils_
- Defined in:
- lib/bundler/vendor/fileutils/lib/fileutils.rb
Overview
:nodoc: internal use only
Constant Summary collapse
- S_IF_DOOR =
0xD000
Instance Method Summary collapse
- #blockdev? ⇒ Boolean
- #chardev? ⇒ Boolean
- #chmod(mode) ⇒ Object
- #chown(uid, gid) ⇒ Object
- #copy(dest) ⇒ Object
- #copy_file(dest) ⇒ Object
- #copy_metadata(path) ⇒ Object
- #dereference? ⇒ Boolean
- #directory? ⇒ Boolean
- #door? ⇒ Boolean
- #entries ⇒ Object
- #exist? ⇒ Boolean
- #file? ⇒ Boolean
-
#initialize(a, b = nil, deref = false) ⇒ Entry_
constructor
A new instance of Entry_.
- #inspect ⇒ Object
- #lstat ⇒ Object
- #lstat! ⇒ Object
- #path ⇒ Object
- #pipe? ⇒ Boolean
- #platform_support ⇒ Object
- #postorder_traverse ⇒ Object
- #prefix ⇒ Object
- #preorder_traverse ⇒ Object (also: #traverse)
- #rel ⇒ Object
- #remove ⇒ Object
- #remove_dir1 ⇒ Object
- #remove_file ⇒ Object
- #socket? ⇒ Boolean
- #stat ⇒ Object
- #stat! ⇒ Object
- #symlink? ⇒ Boolean
- #wrap_traverse(pre, post) ⇒ Object
Constructor Details
#initialize(a, b = nil, deref = false) ⇒ Entry_
Returns a new instance of Entry_.
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1105 def initialize(a, b = nil, deref = false) @prefix = @rel = @path = nil if b @prefix = a @rel = b else @path = a end @deref = deref @stat = nil @lstat = nil end |
Instance Method Details
#blockdev? ⇒ Boolean
1171 1172 1173 1174 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1171 def blockdev? s = lstat! s and s.blockdev? end |
#chardev? ⇒ Boolean
1166 1167 1168 1169 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1166 def chardev? s = lstat! s and s.chardev? end |
#chmod(mode) ⇒ Object
1237 1238 1239 1240 1241 1242 1243 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1237 def chmod(mode) if symlink? File.lchmod mode, path() if have_lchmod? else File.chmod mode, path() end end |
#chown(uid, gid) ⇒ Object
1245 1246 1247 1248 1249 1250 1251 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1245 def chown(uid, gid) if symlink? File.lchown uid, gid, path() if have_lchown? else File.chown uid, gid, path() end end |
#copy(dest) ⇒ Object
1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1253 def copy(dest) lstat case when file? copy_file dest when directory? if !File.exist?(dest) and descendant_directory?(dest, path) raise ArgumentError, "cannot copy directory %s to itself %s" % [path, dest] end begin Dir.mkdir dest rescue raise unless File.directory?(dest) end when symlink? File.symlink File.readlink(path()), dest when chardev? raise "cannot handle device file" unless File.respond_to?(:mknod) mknod dest, ?c, 0666, lstat().rdev when blockdev? raise "cannot handle device file" unless File.respond_to?(:mknod) mknod dest, ?b, 0666, lstat().rdev when socket? raise "cannot handle socket" unless File.respond_to?(:mknod) mknod dest, nil, lstat().mode, 0 when pipe? raise "cannot handle FIFO" unless File.respond_to?(:mkfifo) mkfifo dest, 0666 when door? raise "cannot handle door: #{path()}" else raise "unknown file type: #{path()}" end end |
#copy_file(dest) ⇒ Object
1288 1289 1290 1291 1292 1293 1294 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1288 def copy_file(dest) File.open(path()) do |s| File.open(dest, 'wb', s.stat.mode) do |f| IO.copy_stream(s, f) end end end |
#copy_metadata(path) ⇒ Object
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1296 def (path) st = lstat() if !st.symlink? File.utime st.atime, st.mtime, path end mode = st.mode begin if st.symlink? begin File.lchown st.uid, st.gid, path rescue NotImplementedError end else File.chown st.uid, st.gid, path end rescue Errno::EPERM, Errno::EACCES # clear setuid/setgid mode &= 01777 end if st.symlink? begin File.lchmod mode, path rescue NotImplementedError end else File.chmod mode, path end end |
#dereference? ⇒ Boolean
1138 1139 1140 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1138 def dereference? @deref end |
#directory? ⇒ Boolean
1156 1157 1158 1159 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1156 def directory? s = lstat! s and s.directory? end |
#door? ⇒ Boolean
1188 1189 1190 1191 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1188 def door? s = lstat! s and (s.mode & 0xF000 == S_IF_DOOR) end |
#entries ⇒ Object
1193 1194 1195 1196 1197 1198 1199 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1193 def entries opts = {} opts[:encoding] = ::Encoding::UTF_8 if fu_windows? Dir.entries(path(), opts)\ .reject {|n| n == '.' or n == '..' }\ .map {|n| Entry_.new(prefix(), join(rel(), n.untaint)) } end |
#exist? ⇒ Boolean
1142 1143 1144 1145 1146 1147 1148 1149 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1142 def exist? begin lstat true rescue Errno::ENOENT false end end |
#file? ⇒ Boolean
1151 1152 1153 1154 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1151 def file? s = lstat! s and s.file? end |
#inspect ⇒ Object
1118 1119 1120 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1118 def inspect "\#<#{self.class} #{path()}>" end |
#lstat ⇒ Object
1223 1224 1225 1226 1227 1228 1229 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1223 def lstat if dereference? @lstat ||= File.stat(path()) else @lstat ||= File.lstat(path()) end end |
#lstat! ⇒ Object
1231 1232 1233 1234 1235 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1231 def lstat! lstat() rescue SystemCallError nil end |
#path ⇒ Object
1122 1123 1124 1125 1126 1127 1128 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1122 def path if @path File.path(@path) else join(@prefix, @rel) end end |
#pipe? ⇒ Boolean
1181 1182 1183 1184 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1181 def pipe? s = lstat! s and s.pipe? end |
#platform_support ⇒ Object
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1345 def platform_support return yield unless fu_windows? first_time_p = true begin yield rescue Errno::ENOENT raise rescue => err if first_time_p first_time_p = false begin File.chmod 0700, path() # Windows does not have symlink retry rescue SystemCallError end end raise err end end |
#postorder_traverse ⇒ Object
1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1375 def postorder_traverse if directory? entries().each do |ent| ent.postorder_traverse do |e| yield e end end end ensure yield self end |
#prefix ⇒ Object
1130 1131 1132 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1130 def prefix @prefix || @path end |
#preorder_traverse ⇒ Object Also known as: traverse
1365 1366 1367 1368 1369 1370 1371 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1365 def preorder_traverse stack = [self] while ent = stack.pop yield ent stack.concat ent.entries.reverse if ent.directory? end end |
#rel ⇒ Object
1134 1135 1136 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1134 def rel @rel end |
#remove ⇒ Object
1325 1326 1327 1328 1329 1330 1331 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1325 def remove if directory? remove_dir1 else remove_file end end |
#remove_dir1 ⇒ Object
1333 1334 1335 1336 1337 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1333 def remove_dir1 platform_support { Dir.rmdir path().chomp(?/) } end |
#remove_file ⇒ Object
1339 1340 1341 1342 1343 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1339 def remove_file platform_support { File.unlink path } end |
#socket? ⇒ Boolean
1176 1177 1178 1179 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1176 def socket? s = lstat! s and s.socket? end |
#stat ⇒ Object
1201 1202 1203 1204 1205 1206 1207 1208 1209 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1201 def stat return @stat if @stat if lstat() and lstat().symlink? @stat = File.stat(path()) else @stat = lstat() end @stat end |
#stat! ⇒ Object
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1211 def stat! return @stat if @stat if lstat! and lstat!.symlink? @stat = File.stat(path()) else @stat = lstat! end @stat rescue SystemCallError nil end |
#symlink? ⇒ Boolean
1161 1162 1163 1164 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1161 def symlink? s = lstat! s and s.symlink? end |
#wrap_traverse(pre, post) ⇒ Object
1387 1388 1389 1390 1391 1392 1393 1394 1395 |
# File 'lib/bundler/vendor/fileutils/lib/fileutils.rb', line 1387 def wrap_traverse(pre, post) pre.call self if directory? entries.each do |ent| ent.wrap_traverse pre, post end end post.call self end |