fakefs 0.14.3 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c09661ba99df9e1fb6dda087536caea4b5ddfafba0e5b1b988c27714bc6bed30
4
- data.tar.gz: 9efbcef34fb31915d392b6ed385fa97579a903b04310159a9eebceade144f4fd
3
+ metadata.gz: 4a4da28e46b56875973439b5aaee5395293a8d0fff5e7a72f25e0dbd1ea12dee
4
+ data.tar.gz: da232cb25e279d1c932ceeb0fa52f016f6e3ce7b208b42aca72c8609e1c235b2
5
5
  SHA512:
6
- metadata.gz: 783b8482794a481d30afdc4f5b1494101db78317b82d509e446550bee3beabfde5962de41f7f0a96c2eb6d98b2f053fedc646518ad5c52f326aac02df92022fc
7
- data.tar.gz: 202684637a431531d8378ae01d8205379e0ec2f1408f7a96fa8a29e6399d2a47941c14b75636ede97a254131f7fec884ebcd068133b057600c14fd97598db138
6
+ metadata.gz: 7d2d9f03153e6c42aeb5441b171ec8903b5b2b64939474dfa6f2e7f6d6bfdb59ba4147c19ed4975377633a8d3dbab25e1eed1a23a3e53f7240e9bef7a55fab87
7
+ data.tar.gz: 105499836a07529c55b9efd8a3313fe02bf42cfb52a23e6854935ef45eb7e516aeba2265c6652bc21d314c0496c03e39edd993ec209957de5d77cc9cfaf02363
data/lib/fakefs/dir.rb CHANGED
@@ -13,10 +13,11 @@ module FakeFS
13
13
  def initialize(string)
14
14
  self.class._check_for_valid_file(string)
15
15
 
16
- @path = FileSystem.normalize_path(string)
17
- @open = true
18
- @pointer = 0
16
+ @path = FileSystem.normalize_path(string)
17
+ @open = true
18
+ @pointer = 0
19
19
  @contents = ['.', '..'] + FileSystem.find(@path).entries
20
+ @inode = FakeInode.new(self)
20
21
  end
21
22
 
22
23
  def close
@@ -218,6 +219,10 @@ module FakeFS
218
219
  end
219
220
  end
220
221
 
222
+ def ino
223
+ @inode.inode_num
224
+ end
225
+
221
226
  # This code has been borrowed from Rubinius
222
227
  def self.mktmpdir(prefix_suffix = nil, tmpdir = nil)
223
228
  case prefix_suffix
@@ -1,7 +1,7 @@
1
1
  module FakeFS
2
2
  # Fake Dir class
3
3
  class FakeDir
4
- attr_accessor :name, :parent, :mode, :uid, :gid, :mtime, :atime
4
+ attr_accessor :name, :parent, :mode, :uid, :gid, :mtime, :atime, :inode
5
5
  attr_reader :ctime, :content
6
6
 
7
7
  def initialize(name = nil, parent = nil)
@@ -13,6 +13,7 @@ module FakeFS
13
13
  @mode = 0o100000 + (0o777 - File.umask)
14
14
  @uid = Process.uid
15
15
  @gid = Process.gid
16
+ @inode = FakeInode.new(self)
16
17
  @content = ''
17
18
  @entries = {}
18
19
  end
@@ -32,6 +33,7 @@ module FakeFS
32
33
  value.parent = clone
33
34
  end
34
35
  clone.parent = parent if parent
36
+ clone.inode = @inode.clone
35
37
  clone
36
38
  end
37
39
 
@@ -68,6 +70,7 @@ module FakeFS
68
70
  def delete(node = self)
69
71
  if node == self
70
72
  parent.delete(self)
73
+ @inode.free_inode_num
71
74
  else
72
75
  @entries.delete(node.name)
73
76
  end
@@ -4,36 +4,10 @@ module FakeFS
4
4
  attr_accessor :name, :parent, :mtime, :atime, :mode, :uid, :gid
5
5
  attr_reader :ctime, :birthtime
6
6
 
7
- # Inode class
8
- class Inode
9
- def initialize(file_owner)
10
- @content = ''.encode(Encoding.default_external)
11
- @links = [file_owner]
12
- end
13
-
14
- attr_accessor :content
15
- attr_accessor :links
16
-
17
- def link(file)
18
- links << file unless links.include?(file)
19
- file.inode = self
20
- end
21
-
22
- def unlink(file)
23
- links.delete(file)
24
- end
25
-
26
- def clone
27
- clone = super
28
- clone.content = content.dup
29
- clone
30
- end
31
- end
32
-
33
7
  def initialize(name = nil, parent = nil)
34
8
  @name = name
35
9
  @parent = parent
36
- @inode = Inode.new(self)
10
+ @inode = FakeInode.new(self)
37
11
  @ctime = Time.now
38
12
  @mtime = @ctime
39
13
  @atime = @ctime
@@ -83,6 +57,7 @@ module FakeFS
83
57
 
84
58
  def delete
85
59
  inode.unlink(self)
60
+ inode.free_inode_num
86
61
  parent.delete(self)
87
62
  end
88
63
  end
@@ -0,0 +1,58 @@
1
+ module FakeFS
2
+ # Inode class
3
+ class FakeInode
4
+ @freed_inodes = []
5
+ @next_inode_num = 0
6
+
7
+ def initialize(file_owner)
8
+ @content = ''.encode(Encoding.default_external)
9
+ @links = [file_owner]
10
+ assign_inode_num
11
+ end
12
+
13
+ attr_accessor :content
14
+ attr_accessor :links
15
+ attr_accessor :inode_num
16
+
17
+ # please see: http://iacobson.net/beware-of-ruby-class-variables/
18
+ class << self
19
+ attr_accessor :freed_inodes
20
+ attr_accessor :next_inode_num
21
+
22
+ # This method should only be used for tests
23
+ # When called, it will reset the current inode information of the FakeFS
24
+ def clear_inode_info_for_tests
25
+ self.freed_inodes = []
26
+ self.next_inode_num = 0
27
+ end
28
+ end
29
+
30
+ def assign_inode_num
31
+ if (@inode_num = self.class.freed_inodes.shift)
32
+ else
33
+ @inode_num = self.class.next_inode_num
34
+ self.class.next_inode_num += 1
35
+ end
36
+ end
37
+
38
+ def free_inode_num
39
+ self.class.freed_inodes.push(@inode_num)
40
+ end
41
+
42
+ def link(file)
43
+ links << file unless links.include?(file)
44
+ file.inode = self
45
+ end
46
+
47
+ def unlink(file)
48
+ links.delete(file)
49
+ end
50
+
51
+ def clone
52
+ clone = super
53
+ clone.content = content.dup
54
+ clone.assign_inode_num
55
+ clone
56
+ end
57
+ end
58
+ end
data/lib/fakefs/file.rb CHANGED
@@ -335,6 +335,8 @@ module FakeFS
335
335
  @mode = @fake_file.mode
336
336
  @uid = @fake_file.uid
337
337
  @gid = @fake_file.gid
338
+ @inode = @fake_file.inode
339
+
338
340
  @birthtime =
339
341
  if @fake_file.respond_to?(:birthtime)
340
342
  @fake_file.birthtime
@@ -401,6 +403,10 @@ module FakeFS
401
403
  size == 0
402
404
  end
403
405
 
406
+ def ino
407
+ @inode.inode_num
408
+ end
409
+
404
410
  include Comparable
405
411
 
406
412
  def <=>(other)
@@ -191,8 +191,8 @@ module FakeFS
191
191
  raise Errno::EEXIST, dest_path unless options[:force]
192
192
  elsif File.directory?(File.dirname(dest_path))
193
193
  FileSystem.delete(dest_path)
194
- FileSystem.add(dest_path, target.entry.clone)
195
194
  FileSystem.delete(path)
195
+ FileSystem.add(dest_path, target.entry.clone)
196
196
  else
197
197
  raise Errno::ENOENT, dest_path unless options[:force]
198
198
  end
data/lib/fakefs/safe.rb CHANGED
@@ -3,6 +3,7 @@ require 'pathname'
3
3
  require 'fakefs/base'
4
4
  require 'fakefs/fake/file'
5
5
  require 'fakefs/fake/dir'
6
+ require 'fakefs/fake/inode'
6
7
  require 'fakefs/fake/symlink'
7
8
  require 'fakefs/file_system'
8
9
  require 'fakefs/fileutils'
@@ -1,7 +1,7 @@
1
1
  module FakeFS
2
2
  # Version module
3
3
  module Version
4
- VERSION = '0.14.3'.freeze
4
+ VERSION = '0.15.0'.freeze
5
5
 
6
6
  def self.to_s
7
7
  VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakefs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.3
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2018-07-07 00:00:00.000000000 Z
15
+ date: 2018-07-09 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bump
@@ -126,6 +126,7 @@ files:
126
126
  - lib/fakefs/dir.rb
127
127
  - lib/fakefs/fake/dir.rb
128
128
  - lib/fakefs/fake/file.rb
129
+ - lib/fakefs/fake/inode.rb
129
130
  - lib/fakefs/fake/symlink.rb
130
131
  - lib/fakefs/file.rb
131
132
  - lib/fakefs/file_system.rb