refile-filesystem-hashed 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +62 -0
- data/LICENSE +22 -0
- data/README.md +19 -0
- data/Rakefile +5 -0
- data/lib/refile/backend/file_system_hashed.rb +34 -0
- data/refile-filesystem-hashed.gemspec +19 -0
- data/spec/refile/file_system_hashed_spec.rb +28 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4b0387d44a6f8c55cc3743d4fb13da5d2c4108ef
|
4
|
+
data.tar.gz: d07a0d64695431cd0a920b0e5d11abd0afb395a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 32a850c81e30212a9d57ba0db4f5d576ea6c61c006213b9867440aa800787f1d68a6cc448077ff7b3f85345b692576ad13a30d0cf5d48599c8076395ee402575
|
7
|
+
data.tar.gz: ed3558cbfa2e9e1f2390264f66a2d3cd523e9aa69eacfec7180ad17e78741fa6edcc9b5a6c98b06a9559030c3064219a8d649354a53f447a481452d413bbd9a1
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.4.0)
|
5
|
+
crack (0.4.3)
|
6
|
+
safe_yaml (~> 1.0.0)
|
7
|
+
diff-lcs (1.2.5)
|
8
|
+
domain_name (0.5.25)
|
9
|
+
unf (>= 0.0.5, < 1.0.0)
|
10
|
+
hashdiff (0.2.3)
|
11
|
+
http-cookie (1.0.2)
|
12
|
+
domain_name (~> 0.5)
|
13
|
+
mime-types (2.99)
|
14
|
+
netrc (0.11.0)
|
15
|
+
rack (1.6.4)
|
16
|
+
rack-protection (1.5.3)
|
17
|
+
rack
|
18
|
+
refile (0.6.2)
|
19
|
+
mime-types
|
20
|
+
rest-client (~> 1.8)
|
21
|
+
sinatra (~> 1.4.5)
|
22
|
+
rest-client (1.8.0)
|
23
|
+
http-cookie (>= 1.0.2, < 2.0)
|
24
|
+
mime-types (>= 1.16, < 3.0)
|
25
|
+
netrc (~> 0.7)
|
26
|
+
rspec (3.4.0)
|
27
|
+
rspec-core (~> 3.4.0)
|
28
|
+
rspec-expectations (~> 3.4.0)
|
29
|
+
rspec-mocks (~> 3.4.0)
|
30
|
+
rspec-core (3.4.1)
|
31
|
+
rspec-support (~> 3.4.0)
|
32
|
+
rspec-expectations (3.4.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.4.0)
|
35
|
+
rspec-mocks (3.4.0)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.4.0)
|
38
|
+
rspec-support (3.4.1)
|
39
|
+
safe_yaml (1.0.4)
|
40
|
+
sinatra (1.4.6)
|
41
|
+
rack (~> 1.4)
|
42
|
+
rack-protection (~> 1.4)
|
43
|
+
tilt (>= 1.3, < 3)
|
44
|
+
tilt (2.0.1)
|
45
|
+
unf (0.1.4)
|
46
|
+
unf_ext
|
47
|
+
unf_ext (0.0.7.1)
|
48
|
+
webmock (1.22.3)
|
49
|
+
addressable (>= 2.3.6)
|
50
|
+
crack (>= 0.3.2)
|
51
|
+
hashdiff
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
ruby
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
refile (~> 0.5)
|
58
|
+
rspec (~> 3.0)
|
59
|
+
webmock
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
1.10.6
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 moviepilot.de
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Refile::Backend::FileSystemHashed
|
2
|
+
|
3
|
+
Refile backend that's based on `Refile::Backend::FileSystem` and stores files in sub-directories based on the given file id instead of storing all files on one directory.
|
4
|
+
|
5
|
+
Refile's out-of-the-box backend `Refile::Backend::FileSystem` stores all files within one directory which can get very large and makes maintenance (`ls`, etc.) very slow. This gem extends the default behavior, it splits up the directory in tiny chunks based on the given file id. For example if there is a file with id `0601ae4450cdc210ab9d05da50c392ee1c4b1894e8b2bc9cc5cc9e41e691` it stores the file in the nested directory `06/01/ae/44/0601ae4450cdc210ab9d05da50c392ee1c4b1894e8b2bc9cc5cc9e41e691` within the given directory.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
Add `refile-filesystem-hashed` to your Gemfile.
|
10
|
+
|
11
|
+
gem 'refile-filesystem-hashed', '~> 1.0.1', require: 'refile/backend/file_system_hashed'
|
12
|
+
|
13
|
+
Replace `Refile::Backend::FileSystem` with `Refile::Backend::FileSystemHashed`.
|
14
|
+
|
15
|
+
backend = Refile::Backend::FileSystemHashed.new("/uploads")
|
16
|
+
backend.path('0601ae4450cdc210ab9d05da50c392ee1c4b1894e8b2bc9cc5cc9e41e691')
|
17
|
+
=> "/uploads/06/01/ae/44/0601ae4450cdc210ab9d05da50c392ee1c4b1894e8b2bc9cc5cc9e41e691"
|
18
|
+
|
19
|
+
You can replace `Refile::Backend::FileSystem` at any time as the gem will automagically move existing files to the new hashed directory structure.
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Refile
|
2
|
+
module Backend
|
3
|
+
class FileSystemHashed < FileSystem
|
4
|
+
verify_uploadable def upload(uploadable)
|
5
|
+
id = @hasher.hash(uploadable)
|
6
|
+
path = path(id)
|
7
|
+
FileUtils.mkdir_p(::File.dirname(path))
|
8
|
+
IO.copy_stream(uploadable, path)
|
9
|
+
|
10
|
+
Refile::File.new(self, id)
|
11
|
+
end
|
12
|
+
|
13
|
+
verify_id def exists?(id)
|
14
|
+
return true if ::File.exist?(path(id))
|
15
|
+
|
16
|
+
if ::File.exist?(original_path(id))
|
17
|
+
FileUtils.mkdir_p(::File.dirname(path(id)))
|
18
|
+
FileUtils.mv(original_path(id), path(id))
|
19
|
+
return true
|
20
|
+
end
|
21
|
+
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
25
|
+
verify_id def path(id, create = false)
|
26
|
+
::File.join(@directory, id.scan(/.{2}/).first(4), id)
|
27
|
+
end
|
28
|
+
|
29
|
+
verify_id def original_path(id)
|
30
|
+
::File.join(@directory, id)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = 'refile-filesystem-hashed'
|
6
|
+
spec.version = '1.0.2'
|
7
|
+
spec.authors = ['Tim Bleck']
|
8
|
+
spec.email = ['tim.bleck@webedia-group.com']
|
9
|
+
spec.summary = %q{Refile backend that's based on `Refile::Backend::FileSystem` and stores files in sub-directories based on the given file id instead of storing all files on one directory.}
|
10
|
+
spec.homepage = 'https://github.com/francois2metz/refile-filesystem-hashed'
|
11
|
+
spec.license = 'MIT'
|
12
|
+
|
13
|
+
spec.files = `git ls-files -z`.split("\x0")
|
14
|
+
spec.executables = []
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ['lib']
|
17
|
+
|
18
|
+
spec.add_dependency 'refile', '~> 0.5'
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'refile/spec_helper'
|
2
|
+
require 'refile/backend/file_system_hashed'
|
3
|
+
|
4
|
+
RSpec.describe Refile::Backend::FileSystemHashed do
|
5
|
+
let(:backend) { Refile::Backend::FileSystemHashed.new('tmp', max_size: 100) }
|
6
|
+
|
7
|
+
it_behaves_like :backend
|
8
|
+
|
9
|
+
describe '#path' do
|
10
|
+
let(:orginal_backend) { Refile::Backend::FileSystem.new('tmp', max_size: 100) }
|
11
|
+
let(:uploadable) { Refile::FileDouble.new('hello') }
|
12
|
+
|
13
|
+
it 'generates a hashed path based on the first 8 characters given id' do
|
14
|
+
id = '0601ae4450cdc210ab9d05da50c392ee1c4b1894e8b2bc9cc5cc9e41e691'
|
15
|
+
expect(backend.path(id)).to eq(::File.join(backend.directory, '06', '01', 'ae', '44', id))
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'automagically moves files created with the standard FileSystem backend to the new hashed directory structure' do
|
19
|
+
file = orginal_backend.upload(uploadable)
|
20
|
+
|
21
|
+
backend.path(file.id)
|
22
|
+
|
23
|
+
expect(backend.exists?(file.id)).to be_truthy
|
24
|
+
expect(backend.read(file.id)).to eq('hello')
|
25
|
+
expect(orginal_backend.exists?(file.id)).to be_falsy
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: refile-filesystem-hashed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Bleck
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: refile
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.5'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- tim.bleck@webedia-group.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
37
|
+
- LICENSE
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- lib/refile/backend/file_system_hashed.rb
|
41
|
+
- refile-filesystem-hashed.gemspec
|
42
|
+
- spec/refile/file_system_hashed_spec.rb
|
43
|
+
homepage: https://github.com/francois2metz/refile-filesystem-hashed
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.4.8
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Refile backend that's based on `Refile::Backend::FileSystem` and stores files
|
67
|
+
in sub-directories based on the given file id instead of storing all files on one
|
68
|
+
directory.
|
69
|
+
test_files:
|
70
|
+
- spec/refile/file_system_hashed_spec.rb
|