ramdev 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ramdev +73 -8
- data/lib/ramdev.rb +47 -10
- data/lib/ramdev_sync.rb +24 -3
- metadata +24 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d0dcbbd1cafd549bfc229205292d164511a834e
|
4
|
+
data.tar.gz: 5ffaedf402b00c472dfc42859452da63127f2371
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31e4ca813d43135eedf7a2a74cad872aeb5726cec978e4ff76e794fbdcca2ced68b7350a5b683f850621dc754c4ac0e9d51042232d4cb1361b72aadf0080da58
|
7
|
+
data.tar.gz: 50c04438232f6283ce65300ec917e542bbbc21f3b90e3a7c3c2f53190b68daf1a8e4425176cbf57f1c8c013aebcc009c47ba711115220eecd56688a8a202a5cf
|
data/bin/ramdev
CHANGED
@@ -8,30 +8,95 @@ require 'etc'
|
|
8
8
|
#FIX: This is not windows compatible.
|
9
9
|
|
10
10
|
Main do
|
11
|
+
option('version') do
|
12
|
+
description 'Get version.'
|
13
|
+
end
|
14
|
+
|
15
|
+
option('rcfile', 'r') do
|
16
|
+
argument_required
|
17
|
+
cast :string
|
18
|
+
description 'Manually set the rcfile to use.'
|
19
|
+
end
|
20
|
+
|
11
21
|
mode 'up' do
|
22
|
+
option('memory','m') do
|
23
|
+
argument_required
|
24
|
+
validate {|m| m =~ /[Mm][Bb]|[Gg][Bb]$/}
|
25
|
+
cast :string
|
26
|
+
description 'Optional size of ramdisk in MB or GB, (i.e. -m 300MB)'
|
27
|
+
end
|
28
|
+
|
12
29
|
def run
|
13
30
|
user = Etc.getlogin
|
14
|
-
rcfile
|
31
|
+
if(params['rcfile'].given?)
|
32
|
+
rcfile = params['rcfile'].value
|
33
|
+
else
|
34
|
+
rcfile = File.join(Dir.home(user), ".ramdevrc")
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
if(params['memory'].given?)
|
39
|
+
memString = params['memory'].value
|
40
|
+
|
41
|
+
mem = memString[/^[0-9]+/].to_i * 1048576 if memString =~ /[Mm][Bb]$/
|
42
|
+
mem = memString[/^[0-9]+/].to_i * 1073741824 if memString =~ /[Gg][Bb]$/
|
43
|
+
end
|
15
44
|
|
16
45
|
rd = RamDev.new
|
17
|
-
|
46
|
+
if mem
|
47
|
+
rd.build(rcfile, mem)
|
48
|
+
else
|
49
|
+
rd.build(rcfile)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
mode 'fix' do
|
56
|
+
def run
|
57
|
+
user = Etc.getlogin
|
58
|
+
if(params['rcfile'].given?)
|
59
|
+
rcfile = params['rcfile'].value
|
60
|
+
else
|
61
|
+
rcfile = File.join(Dir.home(user), ".ramdevrc")
|
62
|
+
end
|
63
|
+
|
64
|
+
rd = RamDev.new
|
65
|
+
rd.fix(rcfile)
|
18
66
|
end
|
19
67
|
end
|
20
68
|
|
21
69
|
mode 'down' do
|
70
|
+
option('force', 'f') do
|
71
|
+
description 'Attempt to force ramdisk shutdown even if folder are in a bad state (only used for testing).'
|
72
|
+
end
|
73
|
+
|
22
74
|
def run
|
23
75
|
user = Etc.getlogin
|
24
|
-
rcfile
|
76
|
+
if(params['rcfile'].given?)
|
77
|
+
rcfile = params['rcfile'].value
|
78
|
+
else
|
79
|
+
rcfile = File.join(Dir.home(user), ".ramdevrc")
|
80
|
+
end
|
25
81
|
|
26
82
|
rd = RamDev.new
|
27
|
-
|
83
|
+
if(params['force'].given?)
|
84
|
+
rd.unbuild(rcfile,force: true)
|
85
|
+
else
|
86
|
+
rd.unbuild(rcfile)
|
87
|
+
end
|
88
|
+
|
28
89
|
end
|
29
90
|
end
|
30
91
|
|
31
92
|
def run()
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
93
|
+
if(params['version'].given?)
|
94
|
+
puts 'ramdev v0.2.0'
|
95
|
+
else
|
96
|
+
puts 'Usage: ramdev [up|down]'
|
97
|
+
puts ''
|
98
|
+
puts "\tup\tCreate a ramdisk, move and link working folders."
|
99
|
+
puts "\tdown\tDeallocate ramdisk and restore all file paths."
|
100
|
+
end
|
36
101
|
end
|
37
102
|
end
|
data/lib/ramdev.rb
CHANGED
@@ -2,6 +2,7 @@ require 'ramdisk'
|
|
2
2
|
require 'ramdev_sync'
|
3
3
|
require 'pstore'
|
4
4
|
require 'fileutils'
|
5
|
+
require 'rainbow'
|
5
6
|
|
6
7
|
class RamDev
|
7
8
|
attr_reader :diskname, :ramdisk, :mountpoint
|
@@ -12,11 +13,40 @@ class RamDev
|
|
12
13
|
@store = PStore.new("/tmp/ramdev.pstore")
|
13
14
|
end
|
14
15
|
|
15
|
-
def
|
16
|
+
def fix(rcpath)
|
17
|
+
load_runcom(rcpath)
|
18
|
+
|
19
|
+
watcher = RamDevSync.new(File.open(rcpath))
|
20
|
+
|
21
|
+
if watcher.running?
|
22
|
+
puts `ps #{watcher.pid}`
|
23
|
+
puts "It appears ramdev is still running at pid: #{watcher.pid}.".color(:yellow)
|
24
|
+
puts "Try 'ramdev down' first to fix any file linking problem."
|
25
|
+
puts "Otherwise kill the process first before running 'ramdev fix'."
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
@paths.each do |p|
|
30
|
+
src = p["source"].gsub(/\/+$/,"")
|
31
|
+
if( File.exists?(src+@backupSuffix) )
|
32
|
+
if(!File.exists?(src) || File.symlink?(src))
|
33
|
+
FileUtils.safe_unlink(src) if File.symlink?(src)
|
34
|
+
|
35
|
+
puts "Moving backup: ".color(:green) + "#{src+@backupSuffix} to #{src}"
|
36
|
+
FileUtils.move(src+@backupSuffix, src)
|
37
|
+
else
|
38
|
+
puts "skipping file: ".color(:yellow) + ("#{src}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def unbuild(rcpath, force = false)
|
16
46
|
#TODO force sync
|
17
47
|
load_runcom(rcpath)
|
18
48
|
|
19
|
-
if !restore_folders
|
49
|
+
if !force && !restore_folders
|
20
50
|
puts "Ramdisk shutdown was halted because there was a problem restoring folders."
|
21
51
|
puts "Eject the ramdisk manually once you've sorted out any issues."
|
22
52
|
return
|
@@ -29,6 +59,10 @@ class RamDev
|
|
29
59
|
|
30
60
|
Process.kill("QUIT", pid) if pid
|
31
61
|
|
62
|
+
@store.transaction do |s|
|
63
|
+
s["pid"] = nil
|
64
|
+
end
|
65
|
+
|
32
66
|
ramdisk.unmount
|
33
67
|
ramdisk.deallocate
|
34
68
|
|
@@ -51,14 +85,15 @@ class RamDev
|
|
51
85
|
def build(rcpath, size = nil)
|
52
86
|
@size = size
|
53
87
|
@size ||= memory / 2
|
54
|
-
load_runcom(rcpath)
|
55
|
-
|
56
88
|
|
89
|
+
load_runcom(rcpath)
|
57
90
|
ramdisk = Ramdisk.new(mountpoint)
|
58
91
|
|
59
|
-
|
92
|
+
human_num = "#{@size / 1048576}".reverse.gsub(/...(?=.)/,'\&,').reverse
|
93
|
+
puts "Allocating ramdisk size: #{human_num} MB "
|
94
|
+
|
60
95
|
if( !ramdisk.allocate(@size) )
|
61
|
-
puts "Allocation failed. Size: #{
|
96
|
+
puts "Allocation failed. Size: #{human_num} MB"
|
62
97
|
exit
|
63
98
|
end
|
64
99
|
if( !ramdisk.format(diskname, :hfs) )
|
@@ -72,17 +107,19 @@ class RamDev
|
|
72
107
|
end
|
73
108
|
|
74
109
|
|
75
|
-
|
110
|
+
if !valid_paths?
|
111
|
+
puts "paths are not valid!".color(:red)
|
112
|
+
raise(:hell)
|
113
|
+
end
|
114
|
+
copy_folders
|
76
115
|
|
77
116
|
puts "RAM disk mounted at #{mountpoint}"
|
78
117
|
|
79
118
|
#FIX: Not compatible with Windows:
|
80
119
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
120
|
fork do
|
85
121
|
puts "ramdev_sync pid #{Process.pid}"
|
122
|
+
File.open("/tmp/ramdev_sync.pid", "w") {|f| f.write("#{Process.pid}\n")}
|
86
123
|
|
87
124
|
@store.transaction do |s|
|
88
125
|
s["pid"] = Process.pid
|
data/lib/ramdev_sync.rb
CHANGED
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'listen'
|
4
4
|
require 'yaml'
|
5
|
-
|
6
|
-
# store = PStore.new("ramdev_sync.pstore")
|
5
|
+
require 'pstore'
|
7
6
|
|
8
7
|
class RamDevSync
|
9
8
|
attr_reader :paths, :listener
|
10
9
|
|
11
10
|
def initialize(rcpath, sufix = "_ramdev")
|
11
|
+
@store = PStore.new("/tmp/ramdev.pstore")
|
12
|
+
|
12
13
|
@backupSuffix = sufix
|
13
14
|
load_runcom(rcpath)
|
14
15
|
|
@@ -47,7 +48,27 @@ class RamDevSync
|
|
47
48
|
|
48
49
|
def running?
|
49
50
|
return true if !@listener.nil? && @listener.listen?
|
50
|
-
|
51
|
+
begin
|
52
|
+
pid = @store.transaction do |s|
|
53
|
+
s["pid"]
|
54
|
+
end
|
55
|
+
return false if pid.nil?
|
56
|
+
Process.kill(0, pid)
|
57
|
+
return true
|
58
|
+
#rescue Errno::ESRCH #not running or zombied
|
59
|
+
#rescue Errno::EPERM #permission denied to query
|
60
|
+
rescue
|
61
|
+
@store.transaction do |s|
|
62
|
+
s["pid"] = nil
|
63
|
+
end
|
64
|
+
return false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def pid
|
69
|
+
@store.transaction do |s|
|
70
|
+
s["pid"]
|
71
|
+
end
|
51
72
|
end
|
52
73
|
|
53
74
|
def watchpaths
|
metadata
CHANGED
@@ -1,57 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ramdev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Kolden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: listen
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: main
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: plist
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 3.1.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.1.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rainbow
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.99.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.99.1
|
55
69
|
description: A management tool for creating a ramdrive and syncing folders back to
|
56
70
|
the hard drive automatically while you work.
|
57
71
|
email:
|
@@ -77,12 +91,12 @@ require_paths:
|
|
77
91
|
- lib
|
78
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- -
|
94
|
+
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
98
|
requirements:
|
85
|
-
- -
|
99
|
+
- - ">="
|
86
100
|
- !ruby/object:Gem::Version
|
87
101
|
version: '0'
|
88
102
|
requirements: []
|