file_pool 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/file_pool/version.rb +1 -1
- data/lib/file_pool.rb +33 -20
- metadata +4 -4
data/lib/file_pool/version.rb
CHANGED
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
|
-
|
82
|
-
|
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
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
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-
|
18
|
+
date: 2018-10-21 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|