file_pool 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/file_pool/version.rb +1 -1
  2. data/lib/file_pool.rb +33 -20
  3. metadata +4 -4
@@ -1,3 +1,3 @@
1
1
  module FilePool
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
data/lib/file_pool.rb CHANGED
@@ -70,32 +70,43 @@ module FilePool
70
70
  #
71
71
  # path (String)::
72
72
  # path of the file to add.
73
+ # options (Hash)::
74
+ # :background (true,false) adding large files can take long (esp. with encryption), +true+ won't block, default is +false+
73
75
  #
74
76
  # === Return Value:
75
77
  #
76
78
  # :: *String* containing a new unique ID for the file added.
77
- def self.add! orig_path
79
+ def self.add! orig_path, options = {}
78
80
  newid = uuid
79
- target = path newid
80
81
 
81
- if @@crypted_mode
82
- FileUtils.mkpath(id2dir_secured newid)
83
- path = crypt(orig_path)
84
- else
85
- path = orig_path
86
- FileUtils.mkpath(id2dir newid)
87
- end
82
+ _add = lambda do
83
+ target = path newid
88
84
 
89
- if !@@copy_source and (File.stat(path).dev == File.stat(File.dirname(target)).dev)
90
- FileUtils.link(path, target)
91
- else
92
- FileUtils.copy(path, target)
85
+ if @@crypted_mode
86
+ FileUtils.mkpath(id2dir_secured newid)
87
+ path = crypt(orig_path)
88
+ else
89
+ path = orig_path
90
+ FileUtils.mkpath(id2dir newid)
91
+ end
92
+
93
+ if !@@copy_source and (File.stat(path).dev == File.stat(File.dirname(target)).dev)
94
+ FileUtils.link(path, target)
95
+ else
96
+ FileUtils.copy(path, target)
97
+ end
98
+
99
+ # don't chmod if orginal file is same as target (hard-linked)
100
+ if File.stat(orig_path).ino != File.stat(File.dirname(target)).ino
101
+ FileUtils.chmod(@@mode, target) if @@mode
102
+ FileUtils.chown(@@owner, @@group, target)
103
+ end
93
104
  end
94
105
 
95
- # don't chmod if orginal file is same as target (hard-linked)
96
- if File.stat(orig_path).ino != File.stat(File.dirname(target)).ino
97
- FileUtils.chmod(@@mode, target) if @@mode
98
- FileUtils.chown(@@owner, @@group, target)
106
+ if options[:background]
107
+ Thread.new{ _add.call }
108
+ else
109
+ _add.call
99
110
  end
100
111
 
101
112
  newid
@@ -110,13 +121,15 @@ module FilePool
110
121
  #
111
122
  # source (String)::
112
123
  # path of the file to add.
113
- #
124
+ # options (Hash)::
125
+ # :background (true,false) adding large files can take long (esp. with encryption), +true+ won't block, default is +false+
126
+ #
114
127
  # === Return Value:
115
128
  #
116
129
  # :: *String* containing a new unique ID for the file added.
117
130
  # :: +false+ when the file could not be stored.
118
- def self.add path
119
- self.add!(path)
131
+ def self.add path, options = {}
132
+ self.add!(path, options)
120
133
 
121
134
  rescue Exception
122
135
  return false
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_pool
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 5
10
- version: 0.3.5
9
+ - 6
10
+ version: 0.3.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - "robokopp (Robert Anni\xC3\xA9s)"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2018-10-19 00:00:00 +02:00
18
+ date: 2018-10-21 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency