ftpmvc 0.2.2 → 0.3.0
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.
- checksums.yaml +4 -4
- data/ftpmvc.gemspec +1 -1
- data/lib/ftpmvc/access_filesystem_filter.rb +4 -4
- data/lib/ftpmvc/application.rb +1 -1
- data/lib/ftpmvc/directory.rb +0 -14
- data/lib/ftpmvc/filter.rb +1 -1
- data/lib/ftpmvc/ftpd.rb +2 -0
- data/lib/ftpmvc/ftpd/driver.rb +20 -0
- data/lib/ftpmvc/ftpd/file_system.rb +41 -0
- data/lib/ftpmvc/server.rb +15 -20
- data/lib/ftpmvc/test_helpers.rb +1 -1
- data/lib/ftpmvc/version.rb +1 -1
- data/spec/integration/operation_spec.rb +23 -6
- data/spec/lib/ftpmvc/access_filesystem_filter_spec.rb +0 -15
- data/spec/lib/ftpmvc/directory_spec.rb +0 -19
- data/spec/lib/ftpmvc/server_spec.rb +1 -0
- data/spec/spec_helper.rb +1 -0
- metadata +7 -4
- data/lib/ftpmvc/driver.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf2e9baaad49d9a071156187fb937b34bad1034a
|
4
|
+
data.tar.gz: 8af18d576a62518dc608c109b0a1714857d7c864
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48e3c95a03c80d3765ca612b176a68e28eadebd76d3b6c55164947324edc253bcc2657699e614a96525e3164c2357380d9b2cb9309c867a3a4980e14ae88487f
|
7
|
+
data.tar.gz: 5c232bcd9e543591d318431a41abf286763717a2879267ca6152a867e229787468139b2d47b5c84a15c8aec9b9a2429130d55ed601d6b5ab0749b746cdaf281a
|
data/ftpmvc.gemspec
CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "guard-rspec"
|
24
24
|
spec.add_development_dependency "terminal-notifier-guard"
|
25
25
|
spec.add_development_dependency "codeclimate-test-reporter"
|
26
|
-
spec.add_dependency "
|
26
|
+
spec.add_dependency "ftpd"
|
27
27
|
spec.add_dependency "activesupport"
|
28
28
|
end
|
@@ -12,12 +12,12 @@ module FTPMVC
|
|
12
12
|
@fs.resolve(path).index
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
@fs.resolve(
|
15
|
+
def directory?(path)
|
16
|
+
@fs.resolve(path).kind_of?(Directory)
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
@fs.
|
19
|
+
def exists?(path)
|
20
|
+
not @fs.resolve(path).nil?
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/ftpmvc/application.rb
CHANGED
data/lib/ftpmvc/directory.rb
CHANGED
@@ -11,16 +11,6 @@ module FTPMVC
|
|
11
11
|
instance_eval(&block) if block_given?
|
12
12
|
end
|
13
13
|
|
14
|
-
def size(path)
|
15
|
-
io = get(path)
|
16
|
-
return nil if io.nil?
|
17
|
-
total_size = 0
|
18
|
-
while buffer = io.read(1024)
|
19
|
-
total_size += buffer.size
|
20
|
-
end
|
21
|
-
total_size
|
22
|
-
end
|
23
|
-
|
24
14
|
def get(path)
|
25
15
|
file = resolve(path)
|
26
16
|
file ? file.data : nil
|
@@ -42,10 +32,6 @@ module FTPMVC
|
|
42
32
|
directory_class(name).new(name, &block)
|
43
33
|
end
|
44
34
|
|
45
|
-
def directory?(path)
|
46
|
-
resolve(path).kind_of?(Directory)
|
47
|
-
end
|
48
|
-
|
49
35
|
protected
|
50
36
|
|
51
37
|
def directory(name, &block)
|
data/lib/ftpmvc/filter.rb
CHANGED
data/lib/ftpmvc/ftpd.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'ftpmvc/ftpd/file_system'
|
2
|
+
|
3
|
+
module FTPMVC
|
4
|
+
module Ftpd
|
5
|
+
class Driver
|
6
|
+
def initialize(application)
|
7
|
+
@application = application
|
8
|
+
end
|
9
|
+
|
10
|
+
def authenticate(username, password)
|
11
|
+
@application.authenticate(username, password)
|
12
|
+
end
|
13
|
+
|
14
|
+
def file_system(username)
|
15
|
+
FileSystem.new(@application)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module FTPMVC
|
2
|
+
module Ftpd
|
3
|
+
class FileSystem
|
4
|
+
def initialize(application)
|
5
|
+
@application = application
|
6
|
+
end
|
7
|
+
|
8
|
+
def dir(path)
|
9
|
+
@application.index(path[/^[^*]*/]).map { |node| ::File.join(path, node.name) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def directory?(path)
|
13
|
+
@application.directory?(path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def read(path)
|
17
|
+
yield @application.get(path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def accessible?(path)
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
def exists?(path)
|
25
|
+
@application.exists?(path)
|
26
|
+
end
|
27
|
+
|
28
|
+
def file_info(path)
|
29
|
+
::Ftpd::FileInfo.new(
|
30
|
+
:ftype => directory?(path) ? 'directory' : 'file',
|
31
|
+
:group => 'nogroup',
|
32
|
+
:mode => 0777,
|
33
|
+
:mtime => Time.now,
|
34
|
+
:nlink => 33,
|
35
|
+
:owner => 'nobody',
|
36
|
+
:path => path,
|
37
|
+
:size => 0)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/ftpmvc/server.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
require 'ftpmvc/
|
1
|
+
require 'ftpd'
|
2
|
+
require 'ftpmvc/ftpd'
|
3
3
|
|
4
4
|
module FTPMVC
|
5
5
|
class Server
|
@@ -11,30 +11,25 @@ module FTPMVC
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def start_in_new_thread(application)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
rescue => e
|
21
|
-
$strerr.puts "Server error: #{e.class}: #{e.message}"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
queue.pop
|
14
|
+
driver = Ftpd::Driver.new(application)
|
15
|
+
@server = ::Ftpd::FtpServer.new(driver)
|
16
|
+
@server.interface, @server.port = @address, @port
|
17
|
+
@server.start
|
18
|
+
@port = @server.bound_port
|
19
|
+
self
|
25
20
|
end
|
26
21
|
|
27
22
|
def start(application)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
23
|
+
start_in_new_thread(application)
|
24
|
+
yield self if block_given?
|
25
|
+
# Manter o instance_variable_get até o pull request #29 ser aprovado
|
26
|
+
# o uma nova versão ficar disponível.
|
27
|
+
@server.instance_variable_get(:@server_thread).join
|
28
|
+
# @server.join
|
34
29
|
end
|
35
30
|
|
36
31
|
def stop
|
37
|
-
|
32
|
+
@server.stop
|
38
33
|
end
|
39
34
|
end
|
40
35
|
end
|
data/lib/ftpmvc/test_helpers.rb
CHANGED
data/lib/ftpmvc/version.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require './spec/spec_helper'
|
2
|
-
|
2
|
+
|
3
|
+
require 'ftpmvc'
|
3
4
|
|
4
5
|
describe 'Operation' do
|
5
6
|
before do
|
6
7
|
music_directory_class = Class.new(FTPMVC::Directory) do
|
7
|
-
def
|
8
|
-
|
8
|
+
def index
|
9
|
+
[ FTPMVC::File.new('pink_floyd.mp3') ]
|
9
10
|
end
|
10
11
|
|
11
12
|
def get(path)
|
@@ -39,19 +40,35 @@ describe 'Operation' do
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
describe 'SIZE' do
|
42
|
-
it '
|
43
|
+
it 'is the file size' do
|
43
44
|
with_application(app) do |ftp|
|
44
45
|
ftp.login
|
45
|
-
expect(ftp.size('/music/pink_floyd.mp3')).to eq
|
46
|
+
expect(ftp.size('/music/pink_floyd.mp3')).to eq 7
|
46
47
|
end
|
47
48
|
end
|
48
49
|
end
|
49
50
|
describe 'GET' do
|
50
|
-
it '
|
51
|
+
it 'is the file content' do
|
51
52
|
with_application(app) do |ftp|
|
52
53
|
ftp.login
|
53
54
|
expect(get(ftp, '/music/pink_floyd.mp3')).to eq 'content'
|
54
55
|
end
|
55
56
|
end
|
56
57
|
end
|
58
|
+
describe 'GET' do
|
59
|
+
it 'is the file content' do
|
60
|
+
with_application(app) do |ftp|
|
61
|
+
ftp.login
|
62
|
+
expect(get(ftp, '/music/pink_floyd.mp3')).to eq 'content'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
describe 'MDTM' do
|
67
|
+
it 'is the modification time of a file' do
|
68
|
+
with_application(app) do |ftp|
|
69
|
+
ftp.login
|
70
|
+
expect(ftp.mdtm('/music/pink_floyd.mp3')).to be_a_kind_of String
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
57
74
|
end
|
@@ -57,19 +57,4 @@ describe FTPMVC::AccessFilesystemFilter do
|
|
57
57
|
.to eq 'Pink Floyd'
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
61
|
-
describe '#bytes' do
|
62
|
-
before do
|
63
|
-
allow_any_instance_of(MusicDirectory)
|
64
|
-
.to receive(:get).with('songs.txt')
|
65
|
-
.and_return StringIO.new('Pink Floyd')
|
66
|
-
allow_any_instance_of(MusicDirectory)
|
67
|
-
.to receive(:get).with('documents.txt')
|
68
|
-
.and_return nil
|
69
|
-
end
|
70
|
-
it 'is the return of the directory' do
|
71
|
-
expect(filter.size('/music/songs.txt'))
|
72
|
-
.to eq 10
|
73
|
-
end
|
74
|
-
end
|
75
60
|
end
|
@@ -75,25 +75,6 @@ describe FTPMVC::Directory do
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
describe '#size' do
|
79
|
-
before do
|
80
|
-
allow(documents)
|
81
|
-
.to receive(:get).with('password.txt')
|
82
|
-
.and_return StringIO.new('12345678')
|
83
|
-
allow(documents)
|
84
|
-
.to receive(:get).with('users.txt')
|
85
|
-
.and_return nil
|
86
|
-
end
|
87
|
-
it 'is the size in bytes of #get return' do
|
88
|
-
expect(documents.size('password.txt')).to eq 8
|
89
|
-
end
|
90
|
-
context 'when #get returns nil' do
|
91
|
-
it 'is nil' do
|
92
|
-
expect(documents.size('users.txt')).to be_nil
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
78
|
describe '#get' do
|
98
79
|
let(:password_txt) { FTPMVC::File.new('password.txt') }
|
99
80
|
before do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ftpmvc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- André Aizim Kelmanson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: ftpd
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - '>='
|
@@ -135,11 +135,13 @@ files:
|
|
135
135
|
- lib/ftpmvc/authenticator/basic.rb
|
136
136
|
- lib/ftpmvc/authenticator/promiscuous.rb
|
137
137
|
- lib/ftpmvc/directory.rb
|
138
|
-
- lib/ftpmvc/driver.rb
|
139
138
|
- lib/ftpmvc/file.rb
|
140
139
|
- lib/ftpmvc/filter.rb
|
141
140
|
- lib/ftpmvc/format.rb
|
142
141
|
- lib/ftpmvc/format/csv.rb
|
142
|
+
- lib/ftpmvc/ftpd.rb
|
143
|
+
- lib/ftpmvc/ftpd/driver.rb
|
144
|
+
- lib/ftpmvc/ftpd/file_system.rb
|
143
145
|
- lib/ftpmvc/server.rb
|
144
146
|
- lib/ftpmvc/test_helpers.rb
|
145
147
|
- lib/ftpmvc/version.rb
|
@@ -186,3 +188,4 @@ test_files:
|
|
186
188
|
- spec/lib/ftpmvc/format/csv_spec.rb
|
187
189
|
- spec/lib/ftpmvc/server_spec.rb
|
188
190
|
- spec/spec_helper.rb
|
191
|
+
has_rdoc:
|
data/lib/ftpmvc/driver.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'em-ftpd'
|
2
|
-
require 'ftpmvc/directory'
|
3
|
-
|
4
|
-
module FTPMVC
|
5
|
-
class Driver
|
6
|
-
def initialize(application)
|
7
|
-
@application = application
|
8
|
-
end
|
9
|
-
|
10
|
-
def dir_contents(path)
|
11
|
-
yield @application.index(path).map { |node| EM::FTPD::DirectoryItem.new(name: node.name) }
|
12
|
-
end
|
13
|
-
|
14
|
-
def authenticate(username, password)
|
15
|
-
yield @application.authenticate(username, password)
|
16
|
-
end
|
17
|
-
|
18
|
-
def change_dir(path)
|
19
|
-
yield @application.directory?(path)
|
20
|
-
end
|
21
|
-
|
22
|
-
def get_file(path)
|
23
|
-
yield @application.get(path)
|
24
|
-
end
|
25
|
-
|
26
|
-
def bytes(path)
|
27
|
-
yield @application.size(path)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|