fssm 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  ---
2
+ :patch: 2
3
+ :build:
2
4
  :major: 0
3
5
  :minor: 2
4
- :patch: 1
5
- :build:
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fssm}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Travis Tilley"]
12
- s.date = %q{2010-12-10}
12
+ s.date = %q{2010-12-11}
13
13
  s.description = %q{file system state monitor}
14
14
  s.email = %q{ttilley@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -78,7 +78,7 @@ class FSSM::Path
78
78
 
79
79
  def split_path(path)
80
80
  path = FSSM::Pathname.for(path)
81
- [@path, (path.relative? ? path : path.relative_path_from(@path))]
81
+ [@path.to_s, (path.relative? ? path : path.relative_path_from(@path)).to_s]
82
82
  end
83
83
 
84
84
  def set_path(path)
@@ -1,503 +1,31 @@
1
1
  require 'fileutils'
2
2
  require 'find'
3
+ require 'pathname'
3
4
 
4
5
  module FSSM
5
- class Pathname < String
6
- SYMLOOP_MAX = 8
7
-
8
- ROOT = '/'.freeze
9
- DOT = '.'.freeze
10
- DOT_DOT = '..'.freeze
6
+ class Pathname < ::Pathname
7
+ ROOT = '/'.freeze
11
8
 
12
9
  class << self
13
10
  def for(path)
14
- path.is_a?(::FSSM::Pathname) ? path : new(path.to_s)
11
+ path.is_a?(Pathname) ? path : new(path)
15
12
  end
16
- end
17
-
18
- def initialize(path)
19
- raise ArgumentError, "path cannot contain ASCII NULLs" if path.to_s =~ %r{\0}
20
- super(path.to_s)
21
- end
22
-
23
- def <=>(other)
24
- self.tr('/', "\0").to_s <=> other.to_str.tr('/', "\0")
25
- rescue NoMethodError
26
- nil
27
- end
28
-
29
- def ==(other)
30
- left = self.cleanpath.tr('/', "\0").to_s
31
- right = self.class.for(other).cleanpath.tr('/', "\0").to_s
32
-
33
- left == right
34
- rescue NoMethodError
35
- false
36
- end
37
-
38
- def +(path)
39
- dup << path
40
- end
41
-
42
- def <<(path)
43
- replace( join(path).cleanpath! )
44
- end
45
-
46
- def absolute?
47
- self[0, 1].to_s == ROOT
48
- end
49
-
50
- def ascend
51
- parts = to_a
52
- parts.length.downto(1) do |i|
53
- yield self.class.join(parts[0, i])
54
- end
55
- end
56
-
57
- def children
58
- entries[2..-1]
59
- end
60
-
61
- def cleanpath!
62
- parts = to_a
63
- final = []
64
-
65
- parts.each do |part|
66
- case part
67
- when DOT then
68
- next
69
- when DOT_DOT then
70
- case final.last
71
- when ROOT then
72
- next
73
- when DOT_DOT then
74
- final.push(DOT_DOT)
75
- when nil then
76
- final.push(DOT_DOT)
77
- else
78
- final.pop
79
- end
80
- else
81
- final.push(part)
82
- end
83
- end
84
-
85
- replace(final.empty? ? DOT : self.class.join(*final))
86
- end
87
-
88
- def cleanpath
89
- dup.cleanpath!
90
- end
91
13
 
92
- def descend
93
- parts = to_a
94
- 1.upto(parts.length) { |i| yield self.class.join(parts[0, i]) }
14
+ alias :[] :glob
95
15
  end
96
16
 
97
- def dot?
98
- self == DOT
99
- end
100
-
101
- def dot_dot?
102
- self == DOT_DOT
103
- end
104
-
105
- def each_filename(&blk)
106
- to_a.each(&blk)
107
- end
108
-
109
- def mountpoint?
110
- stat1 = self.lstat
111
- stat2 = self.parent.lstat
112
-
113
- stat1.dev != stat2.dev || stat1.ino == stat2.ino
114
- rescue Errno::ENOENT
115
- false
116
- end
117
-
118
- def parent
119
- self + '..'
120
- end
121
-
122
- def realpath
123
- path = self
124
-
125
- SYMLOOP_MAX.times do
126
- link = path.readlink
127
- link = path.dirname + link if link.relative?
128
- path = link
129
- end
130
-
131
- raise Errno::ELOOP, self
132
- rescue Errno::EINVAL
133
- path.expand_path
134
- end
135
-
136
- def relative?
137
- !absolute?
138
- end
139
-
140
- def relative_path_from(base)
141
- base = self.class.for(base)
142
-
143
- raise ArgumentError, 'no relative path between a relative and absolute' if self.absolute? != base.absolute?
144
-
145
- return self if base.dot?
146
- return self.class.new(DOT) if self == base
147
-
148
- base = base.cleanpath.to_a
149
- dest = self.cleanpath.to_a
150
-
151
- while !dest.empty? && !base.empty? && dest[0] == base[0]
152
- base.shift
153
- dest.shift
154
- end
155
-
156
- base.shift if base[0] == DOT
157
- dest.shift if dest[0] == DOT
158
-
159
- raise ArgumentError, "base directory may not contain '#{DOT_DOT}'" if base.include?(DOT_DOT)
160
-
161
- path = base.fill(DOT_DOT) + dest
162
- path = self.class.join(*path)
163
- path = self.class.new(DOT) if path.empty?
164
-
165
- path
166
- end
167
-
168
- def root?
169
- !!(self =~ %r{^#{ROOT}+$})
170
- end
171
-
172
- def to_a
173
- array = to_s.split(File::SEPARATOR)
17
+ def segments
18
+ path = to_s
19
+ array = path.split(File::SEPARATOR)
174
20
  array.delete('')
175
- array.insert(0, ROOT) if absolute?
21
+ array.insert(0, ROOT) if path[0,1] == ROOT
176
22
  array
177
23
  end
178
24
 
179
- alias segments to_a
180
-
181
- def to_path
182
- self
183
- end
184
-
185
- def to_s
186
- # this is required to work in rubinius
187
- String.allocate.replace(self)
188
- end
189
-
190
- alias to_str to_s
191
-
192
- def unlink
193
- Dir.unlink(self.to_s)
194
- true
195
- rescue Errno::ENOTDIR
196
- File.unlink(self.to_s)
197
- true
198
- end
199
- end
200
-
201
- class Pathname
202
- def self.[](pattern)
203
- Dir[pattern].map! {|d| FSSM::Pathname.new(d) }
204
- end
205
-
206
- def self.pwd
207
- FSSM::Pathname.new(Dir.pwd)
208
- end
209
-
210
- def entries
211
- Dir.entries(self.to_s).map! {|e| FSSM::Pathname.new(e) }
212
- end
213
-
214
- def mkdir(mode = 0777)
215
- Dir.mkdir(self.to_s, mode)
216
- end
217
-
218
- def opendir(&blk)
219
- Dir.open(self.to_s, &blk)
220
- end
221
-
222
- def rmdir
223
- Dir.rmdir(self.to_s)
224
- end
225
-
226
- def self.glob(pattern, flags = 0)
227
- dirs = Dir.glob(pattern, flags)
228
- dirs.map! {|path| FSSM::Pathname.new(path) }
229
-
230
- if block_given?
231
- dirs.each {|dir| yield dir }
232
- nil
233
- else
234
- dirs
235
- end
236
- end
237
-
238
25
  def glob(pattern, flags = 0, &block)
239
26
  patterns = [pattern].flatten
240
- patterns.map! {|p| self.class.glob(self.to_s + p, flags, &block) }
27
+ patterns.map! {|p| self.class.glob(to_s + p, flags, &block) }
241
28
  patterns.flatten
242
29
  end
243
-
244
- def chdir
245
- blk = lambda { yield self } if block_given?
246
- Dir.chdir(self.to_s, &blk)
247
- end
248
- end
249
-
250
- class Pathname
251
- def blockdev?
252
- FileTest.blockdev?(self.to_s)
253
- end
254
-
255
- def chardev?
256
- FileTest.chardev?(self.to_s)
257
- end
258
-
259
- def directory?
260
- FileTest.directory?(self.to_s)
261
- end
262
-
263
- def executable?
264
- FileTest.executable?(self.to_s)
265
- end
266
-
267
- def executable_real?
268
- FileTest.executable_real?(self.to_s)
269
- end
270
-
271
- def exists?
272
- FileTest.exists?(self.to_s)
273
- end
274
-
275
- def file?
276
- FileTest.file?(self.to_s)
277
- end
278
-
279
- def grpowned?
280
- FileTest.grpowned?(self.to_s)
281
- end
282
-
283
- def owned?
284
- FileTest.owned?(self.to_s)
285
- end
286
-
287
- def pipe?
288
- FileTest.pipe?(self.to_s)
289
- end
290
-
291
- def readable?
292
- FileTest.readable?(self.to_s)
293
- end
294
-
295
- def readable_real?
296
- FileTest.readable_real?(self.to_s)
297
- end
298
-
299
- def setgid?
300
- FileTest.setgit?(self.to_s)
301
- end
302
-
303
- def setuid?
304
- FileTest.setuid?(self.to_s)
305
- end
306
-
307
- def socket?
308
- FileTest.socket?(self.to_s)
309
- end
310
-
311
- def sticky?
312
- FileTest.sticky?(self.to_s)
313
- end
314
-
315
- def symlink?
316
- FileTest.symlink?(self.to_s)
317
- end
318
-
319
- def world_readable?
320
- FileTest.world_readable?(self.to_s)
321
- end
322
-
323
- def world_writable?
324
- FileTest.world_writable?(self.to_s)
325
- end
326
-
327
- def writable?
328
- FileTest.writable?(self.to_s)
329
- end
330
-
331
- def writable_real?
332
- FileTest.writable_real?(self.to_s)
333
- end
334
-
335
- def zero?
336
- FileTest.zero?(self.to_s)
337
- end
338
- end
339
-
340
- class Pathname
341
- def atime
342
- File.atime(self.to_s)
343
- end
344
-
345
- def ctime
346
- File.ctime(self.to_s)
347
- end
348
-
349
- def ftype
350
- File.ftype(self.to_s)
351
- end
352
-
353
- def lstat
354
- File.lstat(self.to_s)
355
- end
356
-
357
- def mtime
358
- File.mtime(self.to_s)
359
- end
360
-
361
- def stat
362
- File.stat(self.to_s)
363
- end
364
-
365
- def utime(atime, mtime)
366
- File.utime(self.to_s, atime, mtime)
367
- end
368
- end
369
-
370
- class Pathname
371
- def self.join(*parts)
372
- last_part = FSSM::Pathname.new(parts.last)
373
- return last_part if last_part.absolute?
374
- FSSM::Pathname.new(File.join(*parts.reject {|p| p.empty? }))
375
- end
376
-
377
- def basename
378
- self.class.new(File.basename(self.to_s))
379
- end
380
-
381
- def chmod(mode)
382
- File.chmod(mode, self.to_s)
383
- end
384
-
385
- def chown(owner, group)
386
- File.chown(owner, group, self.to_s)
387
- end
388
-
389
- def dirname
390
- self.class.new(File.dirname(self.to_s))
391
- end
392
-
393
- def expand_path(from = nil)
394
- self.class.new(File.expand_path(self.to_s, from))
395
- end
396
-
397
- def extname
398
- File.extname(self.to_s)
399
- end
400
-
401
- def fnmatch?(pat, flags = 0)
402
- File.fnmatch(pat, self.to_s, flags)
403
- end
404
-
405
- def join(*parts)
406
- self.class.join(self.to_s, *parts)
407
- end
408
-
409
- def lchmod(mode)
410
- File.lchmod(mode, self.to_s)
411
- end
412
-
413
- def lchown(owner, group)
414
- File.lchown(owner, group, self.to_s)
415
- end
416
-
417
- def link(to)
418
- File.link(self.to_s, to)
419
- end
420
-
421
- def open(mode = 'r', perm = nil, &blk)
422
- File.open(self.to_s, mode, perm, &blk)
423
- end
424
-
425
- def readlink
426
- self.class.new(File.readlink(self.to_s))
427
- end
428
-
429
- def rename(to)
430
- File.rename(self.to_s, to)
431
- replace(to)
432
- end
433
-
434
- def size
435
- File.size(self.to_s)
436
- end
437
-
438
- def size?
439
- File.size?(self.to_s)
440
- end
441
-
442
- def split
443
- File.split(self.to_s).map {|part| FSSM::Pathname.new(part) }
444
- end
445
-
446
- def symlink(to)
447
- File.symlink(self.to_s, to)
448
- end
449
-
450
- def truncate(size)
451
- File.truncate(self.to_s, size)
452
- end
453
- end
454
-
455
- class Pathname
456
- def mkpath
457
- self.class.new(FileUtils.mkpath(self.to_s))
458
- end
459
-
460
- def rmtree
461
- self.class.new(FileUtils.rmtree(self.to_s).first)
462
- end
463
-
464
- def touch
465
- self.class.new(FileUtils.touch(self.to_s).first)
466
- end
467
- end
468
-
469
- class Pathname
470
- def each_line(sep = $/, &blk)
471
- IO.foreach(self.to_s, sep, &blk)
472
- end
473
-
474
- def read(len = nil, off = 0)
475
- IO.read(self.to_s, len, off)
476
- end
477
-
478
- def readlines(sep = $/)
479
- IO.readlines(self.to_s, sep)
480
- end
481
-
482
- def sysopen(mode = 'r', perm = nil)
483
- IO.sysopen(self.to_s, mode, perm)
484
- end
485
- end
486
-
487
- class Pathname
488
- def find
489
- Find.find(self.to_s) {|path| yield FSSM::Pathname.new(path) }
490
- end
491
- end
492
-
493
- class Pathname
494
- class << self
495
- alias getwd pwd
496
- end
497
-
498
- alias absolute expand_path
499
- alias delete unlink
500
- alias exist? exists?
501
- alias fnmatch fnmatch?
502
30
  end
503
31
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fssm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Travis Tilley
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-10 00:00:00 -05:00
18
+ date: 2010-12-11 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency