rwdaddresses 0.95 → 0.97
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.txt +13 -1
- data/code/01rwdcore/03helptexthash.rb +11 -28
- data/code/01rwdcore/openhelpwindow.rb +10 -24
- data/code/01rwdcore/returntomain.rb +10 -0
- data/code/superant.com.rwdaddresses/helptexthashrwdaddresses.rb +27 -11
- data/code/superant.com.rwdaddresses/openhelpwindowrwdaddresses.rb +12 -7
- data/code/superant.com.rwdaddresses/returntomain.rb +10 -0
- data/code/superant.com.rwdaddresses/runaddresseswindow.rb +2 -1
- data/code/superant.com.rwdaddresses/runrwdaddressesmenu1.rb +34 -0
- data/code/superant.com.rwdaddresses/rwdaddressesbackwindow.rb +10 -0
- data/code/superant.com.rwdtinkerbackwindow/controlclient.rb +100 -0
- data/code/superant.com.rwdtinkerbackwindow/helptexthashtinkerwin2.rb +37 -0
- data/code/superant.com.rwdtinkerbackwindow/installapplet.rb +8 -8
- data/code/superant.com.rwdtinkerbackwindow/network.rb +87 -0
- data/code/superant.com.rwdtinkerbackwindow/openhelpwindowtinkerwin2.rb +39 -0
- data/code/superant.com.rwdtinkerbackwindow/runrwdtinkerbackwindow.rb +1 -1
- data/code/superant.com.rwdtinkerbackwindow/viewappletcontents.rb +21 -0
- data/configuration/rwdaddressesversion.cnf +1 -1
- data/configuration/rwdapplicationidentity.cnf +3 -0
- data/configuration/rwdtinker.cnf +1 -0
- data/configuration/rwdtinkerversion.cnf +1 -1
- data/ev/rwd.rb +4 -3
- data/extras/zip/ioextras.rb +114 -0
- data/extras/zip/stdrubyext.rb +111 -0
- data/extras/zip/tempfile_bugfixed.rb +195 -0
- data/extras/zip/zip.rb +1376 -0
- data/extras/zip/zipfilesystem.rb +558 -0
- data/extras/zip/ziprequire.rb +61 -0
- data/gui/00coreguibegin/applicationguitop.rwd +1 -1
- data/gui/frontwindow0/superant.com.rwdaddresses/16editrecord.rwd +9 -9
- data/gui/frontwindow0/superant.com.rwdaddresses/18contactutilities.rwd +1 -0
- data/gui/frontwindow0/superant.com.rwdaddresses/m01menubegin.rwd +10 -0
- data/gui/frontwindow0/superant.com.rwdaddresses/m02menu.rwd +36 -0
- data/gui/frontwindow0/superant.com.rwdaddresses/m03menu.rwd +12 -0
- data/gui/frontwindow0/superant.com.rwdaddresses/m85menu.rwd +21 -0
- data/gui/frontwindow0/superant.com.rwdaddresses/m88menu.rwd +12 -0
- data/gui/frontwindow0/superant.com.rwdaddresses/m99menuend.rwd +3 -0
- data/gui/tinkerbackwindows/superant.com.addressesphotowindow/yy7addressesphoto.rwd +2 -1
- data/gui/{frontwindow0/superant.com.rwdaddresses/zviewconfiguration.rwd → tinkerbackwindows/superant.com.rwdaddressessyncbackwindow/88viewconfiguration.rwd} +9 -9
- data/gui/tinkerbackwindows/superant.com.rwdaddressessyncbackwindow/m01menubegin.rwd +10 -0
- data/gui/tinkerbackwindows/superant.com.rwdaddressessyncbackwindow/m02menu.rwd +36 -0
- data/gui/tinkerbackwindows/superant.com.rwdaddressessyncbackwindow/m03menu.rwd +12 -0
- data/gui/tinkerbackwindows/superant.com.rwdaddressessyncbackwindow/m85menu.rwd +21 -0
- data/gui/tinkerbackwindows/superant.com.rwdaddressessyncbackwindow/m88menu.rwd +18 -0
- data/gui/tinkerbackwindows/superant.com.rwdaddressessyncbackwindow/m99menuend.rwd +3 -0
- data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/{50rwdlistzips.rwd → 40rwdlistzips.rwd} +10 -3
- data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/50rwdlistapplets.rwd +1 -1
- data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/60editconfiguration.rwd +11 -10
- data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/75rwdcontrol.rwd +33 -0
- data/gui/tinkerbackwindows/superant.com.tinkerbackwindow/80tab1.rwd +1 -1
- data/gui/tinkerbackwindows/superant.com.tinkerhelpwindow/1appname.rwd +1 -2
- data/init.rb +38 -2
- data/installed/addressessample1.inf +5 -0
- data/rwd_files/HowTo_Addresses.txt +13 -1
- data/rwd_files/HowTo_Tinker.txt +19 -6
- data/rwd_files/contacttmp.jpg +0 -0
- data/tests/rwdtinkertestEN.rb +163 -0
- data/tests/test.result +32 -0
- data/zips/rwdaschedule-0.921.zip +0 -0
- data/zips/rwdcalc-0.4.zip +0 -0
- metadata +86 -54
- data/gui/tinkerbackwindows/superant.com.rwdaddressessyncbackwindow/22viewconfiguration.rwd +0 -16
- data/gui/tinkerbackwindows/superant.com.rwdaddressessyncbackwindow/80returntab.rwd +0 -11
- data/installed/rwdviewlogo-0.4.inf +0 -4
@@ -0,0 +1,87 @@
|
|
1
|
+
#!ruby
|
2
|
+
require 'socket' # Network stuff
|
3
|
+
require 'timeout' # Timeout functions
|
4
|
+
|
5
|
+
def network_start
|
6
|
+
if RUBY_PLATFORM != "i386-mswin32"
|
7
|
+
processone = fork {
|
8
|
+
network_demon }
|
9
|
+
Process.detach(processone)
|
10
|
+
|
11
|
+
else
|
12
|
+
puts "fork not tried winXP?"
|
13
|
+
end
|
14
|
+
@viewremotecommandresult = "starting controller on next available port"
|
15
|
+
end
|
16
|
+
|
17
|
+
def network_demon
|
18
|
+
# Find configuration variables
|
19
|
+
host = "127.0.0.1"
|
20
|
+
port = $rwdcontrolports[0].to_i
|
21
|
+
|
22
|
+
openportfound = false
|
23
|
+
until openportfound
|
24
|
+
|
25
|
+
# Create a socket to listen on and bind it to the host and port
|
26
|
+
begin
|
27
|
+
@socket = UDPSocket::new()
|
28
|
+
@socket.bind(host, port)
|
29
|
+
# Rescue the "Address in use" error
|
30
|
+
openportfound = true
|
31
|
+
|
32
|
+
rescue Errno::EADDRINUSE
|
33
|
+
puts "controller startup: Port #{port} on host #{host} is already in use."
|
34
|
+
port=port+1
|
35
|
+
# Rescue the "Address not available' error
|
36
|
+
rescue Errno::EADDRNOTAVAIL
|
37
|
+
puts "Network plugin: Address #{host} is not available to bind."
|
38
|
+
port=port+1
|
39
|
+
# Rescue "permission denied errors
|
40
|
+
rescue Errno::EACCES
|
41
|
+
puts "controller startup: Access denied when binding interface addresses. Did you try to bind a port under 1024 as a regular user?"
|
42
|
+
port=port+1
|
43
|
+
# Rescue all other errors
|
44
|
+
rescue
|
45
|
+
puts "Network plugin: An error occured."
|
46
|
+
port = port+1
|
47
|
+
# Rescue all other errors
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
# Get all acceptable hosts
|
54
|
+
hosts = ["localhost","vaio-sag"]
|
55
|
+
# Do some nice errorchecking
|
56
|
+
if(hosts.type != Array)
|
57
|
+
puts "Network plugin: No hosts found in networkConfig/acceptHosts. Shutting down plugin."
|
58
|
+
return -1 # Return the errorcode for plugin failure
|
59
|
+
end
|
60
|
+
|
61
|
+
# Main loop
|
62
|
+
while(true)
|
63
|
+
# Get data and client data from the client
|
64
|
+
data, info = @socket.recvfrom(256)
|
65
|
+
|
66
|
+
# Is this an acceptable IP address?
|
67
|
+
if(hosts.include?(info[2]) || hosts.include?(info[3]))
|
68
|
+
command, parameter = data.split(';')
|
69
|
+
|
70
|
+
# Command actions
|
71
|
+
command.downcase!()
|
72
|
+
case command
|
73
|
+
|
74
|
+
when 'stop'
|
75
|
+
@socket.send("hello world",0,info[3],info[1].to_i)
|
76
|
+
|
77
|
+
when 'query'
|
78
|
+
@socket.send("#{$rwdapplicationidentity} on port #{$port}",0,info[3],info[1].to_i)
|
79
|
+
|
80
|
+
|
81
|
+
end # case command
|
82
|
+
|
83
|
+
end # Access control if
|
84
|
+
end # while(true)
|
85
|
+
|
86
|
+
end # Network::start()
|
87
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# this code is to call the help window
|
2
|
+
def runhelpwindowtinkerwin2
|
3
|
+
|
4
|
+
# $helptopicsarray = $helptopicsarray | [""]
|
5
|
+
|
6
|
+
$help_topic = "tinkerwin2_help"
|
7
|
+
if @rwd_tab == "rwdzipslister"
|
8
|
+
$help_topic = "tinkerwin2_help"
|
9
|
+
end
|
10
|
+
|
11
|
+
if @rwd_tab == "filelister"
|
12
|
+
$help_topic = "applet_viewing"
|
13
|
+
|
14
|
+
end
|
15
|
+
if @rwd_tab == "zipslister"
|
16
|
+
$help_topic = "applet_installation"
|
17
|
+
|
18
|
+
end
|
19
|
+
if @rwd_tab == "editconfigurationfile"
|
20
|
+
$help_topic = "applet_tinkerbackeditconfiguration"
|
21
|
+
|
22
|
+
end
|
23
|
+
if @rwd_tab == "rwdremotecontrol"
|
24
|
+
$help_topic = "remote_control"
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
if @rwd_window != "rwdtinkerhelpwindow"
|
30
|
+
$previouswindow = @rwd_window
|
31
|
+
$previoustab = @rwd_tab
|
32
|
+
else
|
33
|
+
$previouswindow = @rwd_window
|
34
|
+
$previoustab = @rwd_tab
|
35
|
+
end
|
36
|
+
runhelpwindow
|
37
|
+
end
|
38
|
+
|
39
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
def viewappletcontents
|
2
|
+
require 'fileutils'
|
3
|
+
require 'extras/zip/zip'
|
4
|
+
nametext = "%s" % [@a_installapplet]
|
5
|
+
|
6
|
+
begin # exception trapped block
|
7
|
+
fullname = nametext + ".zip"
|
8
|
+
fileName = File.join($zipslocation,fullname)
|
9
|
+
tempfilecontents = " "
|
10
|
+
zf = Zip::ZipFile.new(fileName)
|
11
|
+
zf.sort.each {
|
12
|
+
|entry|
|
13
|
+
tempfilecontents = tempfilecontents + entry.to_s + "\n"
|
14
|
+
}
|
15
|
+
@appletcontentstext = tempfilecontents
|
16
|
+
|
17
|
+
rescue
|
18
|
+
@installapplettext = "unzip error - error opening applet"
|
19
|
+
end # exception rescue
|
20
|
+
|
21
|
+
end
|
@@ -1,2 +1,2 @@
|
|
1
1
|
|
2
|
-
RwdAddressesVersion = "0.
|
2
|
+
RwdAddressesVersion = "0.97"
|
data/configuration/rwdtinker.cnf
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
|
2
|
-
RwdTinkerVersion = "1.
|
2
|
+
RwdTinkerVersion = "1.50"
|
data/ev/rwd.rb
CHANGED
@@ -267,7 +267,7 @@ class OpenTag
|
|
267
267
|
template = $rwd_html_PDA_1 if pda
|
268
268
|
|
269
269
|
res <<(template(template, args))
|
270
|
-
when "p" then
|
270
|
+
when "p" then res << "<p #{align} > "
|
271
271
|
when "pre" then res << "<pre #{align}>"
|
272
272
|
when "big" then res << "<p #{align}><big>"
|
273
273
|
when "small" then res << "<p #{align}><small>"
|
@@ -308,9 +308,10 @@ class OpenTag
|
|
308
308
|
when "hidden" then res << "<p #{align}><input name='#{@args["name"]}' value='#{value1}' type='hidden'>"
|
309
309
|
when "text"
|
310
310
|
maxlength = ""
|
311
|
-
|
311
|
+
maxlength = "maxlength='%s'" % @args["maxlength"] if @args.include?("maxlength")
|
312
312
|
size = ""
|
313
|
-
size
|
313
|
+
size = "size='%s'" % @args["size"] if @args.include?("size")
|
314
|
+
size = "size='%s'" % 10 if pda
|
314
315
|
res << "<p #{align}><input name='#{@args["name"]}' value='#{value1}' type='text' #{maxlength} #{size}>"
|
315
316
|
oneormorefields << "true"
|
316
317
|
when "textarea"
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module IOExtras
|
2
|
+
module FakeIO
|
3
|
+
def kind_of?(object)
|
4
|
+
object == IO || super
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
# Implements many of the convenience methods of IO
|
9
|
+
# such as gets, getc, readline and readlines
|
10
|
+
# depends on: input_finished?, produce_input and read
|
11
|
+
module AbstractInputStream
|
12
|
+
include Enumerable
|
13
|
+
include FakeIO
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
super
|
17
|
+
@lineno = 0
|
18
|
+
@outputBuffer = ""
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_accessor :lineno
|
22
|
+
|
23
|
+
def readlines(aSepString = $/)
|
24
|
+
retVal = []
|
25
|
+
each_line(aSepString) { |line| retVal << line }
|
26
|
+
return retVal
|
27
|
+
end
|
28
|
+
|
29
|
+
def gets(aSepString=$/)
|
30
|
+
@lineno = @lineno.next
|
31
|
+
return read if aSepString == nil
|
32
|
+
aSepString="#{$/}#{$/}" if aSepString == ""
|
33
|
+
|
34
|
+
bufferIndex=0
|
35
|
+
while ((matchIndex = @outputBuffer.index(aSepString, bufferIndex)) == nil)
|
36
|
+
bufferIndex=@outputBuffer.length
|
37
|
+
if input_finished?
|
38
|
+
return @outputBuffer.empty? ? nil : flush
|
39
|
+
end
|
40
|
+
@outputBuffer << produce_input
|
41
|
+
end
|
42
|
+
sepIndex=matchIndex + aSepString.length
|
43
|
+
return @outputBuffer.slice!(0...sepIndex)
|
44
|
+
end
|
45
|
+
|
46
|
+
def flush
|
47
|
+
retVal=@outputBuffer
|
48
|
+
@outputBuffer=""
|
49
|
+
return retVal
|
50
|
+
end
|
51
|
+
|
52
|
+
def readline(aSepString = $/)
|
53
|
+
retVal = gets(aSepString)
|
54
|
+
raise EOFError if retVal == nil
|
55
|
+
return retVal
|
56
|
+
end
|
57
|
+
|
58
|
+
def each_line(aSepString = $/)
|
59
|
+
while true
|
60
|
+
yield readline(aSepString)
|
61
|
+
end
|
62
|
+
rescue EOFError
|
63
|
+
end
|
64
|
+
|
65
|
+
alias_method :each, :each_line
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
#relies on <<
|
70
|
+
module AbstractOutputStream
|
71
|
+
include FakeIO
|
72
|
+
|
73
|
+
def write(data)
|
74
|
+
self << data
|
75
|
+
data.to_s.length
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
def print(*params)
|
80
|
+
self << params.to_s << $\.to_s
|
81
|
+
end
|
82
|
+
|
83
|
+
def printf(aFormatString, *params)
|
84
|
+
self << sprintf(aFormatString, *params)
|
85
|
+
end
|
86
|
+
|
87
|
+
def putc(anObject)
|
88
|
+
self << case anObject
|
89
|
+
when Fixnum then anObject.chr
|
90
|
+
when String then anObject
|
91
|
+
else raise TypeError, "putc: Only Fixnum and String supported"
|
92
|
+
end
|
93
|
+
anObject
|
94
|
+
end
|
95
|
+
|
96
|
+
def puts(*params)
|
97
|
+
params << "\n" if params.empty?
|
98
|
+
params.flatten.each {
|
99
|
+
|element|
|
100
|
+
val = element.to_s
|
101
|
+
self << val
|
102
|
+
self << "\n" unless val[-1,1] == "\n"
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end # IOExtras namespace module
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
# Copyright (C) 2002-2004 Thomas Sondergaard
|
113
|
+
# rubyzip is free software; you can redistribute it and/or
|
114
|
+
# modify it under the terms of the ruby license.
|
@@ -0,0 +1,111 @@
|
|
1
|
+
unless Enumerable.method_defined?(:inject)
|
2
|
+
module Enumerable #:nodoc:all
|
3
|
+
def inject(n = 0)
|
4
|
+
each { |value| n = yield(n, value) }
|
5
|
+
n
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Enumerable #:nodoc:all
|
11
|
+
# returns a new array of all the return values not equal to nil
|
12
|
+
# This implementation could be faster
|
13
|
+
def select_map(&aProc)
|
14
|
+
map(&aProc).reject { |e| e.nil? }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
unless Object.method_defined?(:object_id)
|
19
|
+
class Object
|
20
|
+
# Using object_id which is the new thing, so we need
|
21
|
+
# to make that work in versions prior to 1.8.0
|
22
|
+
alias object_id id
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
unless File.respond_to?(:read)
|
27
|
+
class File
|
28
|
+
# singleton method read does not exist in 1.6.x
|
29
|
+
def self.read(fileName)
|
30
|
+
open(fileName) { |f| f.read }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class String
|
36
|
+
def starts_with(aString)
|
37
|
+
rindex(aString, 0) == 0
|
38
|
+
end
|
39
|
+
|
40
|
+
def ends_with(aString)
|
41
|
+
index(aString, -aString.size)
|
42
|
+
end
|
43
|
+
|
44
|
+
def ensure_end(aString)
|
45
|
+
ends_with(aString) ? self : self + aString
|
46
|
+
end
|
47
|
+
|
48
|
+
def lchop
|
49
|
+
slice(1, length)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Time
|
54
|
+
|
55
|
+
#MS-DOS File Date and Time format as used in Interrupt 21H Function 57H:
|
56
|
+
#
|
57
|
+
# Register CX, the Time:
|
58
|
+
# Bits 0-4 2 second increments (0-29)
|
59
|
+
# Bits 5-10 minutes (0-59)
|
60
|
+
# bits 11-15 hours (0-24)
|
61
|
+
#
|
62
|
+
# Register DX, the Date:
|
63
|
+
# Bits 0-4 day (1-31)
|
64
|
+
# bits 5-8 month (1-12)
|
65
|
+
# bits 9-15 year (four digit year minus 1980)
|
66
|
+
|
67
|
+
|
68
|
+
def to_binary_dos_time
|
69
|
+
(sec/2) +
|
70
|
+
(min << 5) +
|
71
|
+
(hour << 11)
|
72
|
+
end
|
73
|
+
|
74
|
+
def to_binary_dos_date
|
75
|
+
(day) +
|
76
|
+
(month << 5) +
|
77
|
+
((year - 1980) << 9)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Dos time is only stored with two seconds accuracy
|
81
|
+
def dos_equals(other)
|
82
|
+
to_i/2 == other.to_i/2
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.parse_binary_dos_format(binaryDosDate, binaryDosTime)
|
86
|
+
second = 2 * ( 0b11111 & binaryDosTime)
|
87
|
+
minute = ( 0b11111100000 & binaryDosTime) >> 5
|
88
|
+
hour = (0b1111100000000000 & binaryDosTime) >> 11
|
89
|
+
day = ( 0b11111 & binaryDosDate)
|
90
|
+
month = ( 0b111100000 & binaryDosDate) >> 5
|
91
|
+
year = ((0b1111111000000000 & binaryDosDate) >> 9) + 1980
|
92
|
+
begin
|
93
|
+
return Time.local(year, month, day, hour, minute, second)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
class Module
|
99
|
+
def forward_message(forwarder, *messagesToForward)
|
100
|
+
methodDefs = messagesToForward.map {
|
101
|
+
|msg|
|
102
|
+
"def #{msg}; #{forwarder}(:#{msg}); end"
|
103
|
+
}
|
104
|
+
module_eval(methodDefs.join("\n"))
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
# Copyright (C) 2002, 2003 Thomas Sondergaard
|
110
|
+
# rubyzip is free software; you can redistribute it and/or
|
111
|
+
# modify it under the terms of the ruby license.
|
@@ -0,0 +1,195 @@
|
|
1
|
+
#
|
2
|
+
# tempfile - manipulates temporary files
|
3
|
+
#
|
4
|
+
# $Id: tempfile_bugfixed.rb,v 1.2 2004/03/28 12:46:36 thomas Exp $
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'delegate'
|
8
|
+
require 'tmpdir'
|
9
|
+
|
10
|
+
module BugFix
|
11
|
+
|
12
|
+
# A class for managing temporary files. This library is written to be
|
13
|
+
# thread safe.
|
14
|
+
class Tempfile < DelegateClass(File)
|
15
|
+
MAX_TRY = 10
|
16
|
+
@@cleanlist = []
|
17
|
+
|
18
|
+
# Creates a temporary file of mode 0600 in the temporary directory
|
19
|
+
# whose name is basename.pid.n and opens with mode "w+". A Tempfile
|
20
|
+
# object works just like a File object.
|
21
|
+
#
|
22
|
+
# If tmpdir is omitted, the temporary directory is determined by
|
23
|
+
# Dir::tmpdir provided by 'tmpdir.rb'.
|
24
|
+
# When $SAFE > 0 and the given tmpdir is tainted, it uses
|
25
|
+
# /tmp. (Note that ENV values are tainted by default)
|
26
|
+
def initialize(basename, tmpdir=Dir::tmpdir)
|
27
|
+
if $SAFE > 0 and tmpdir.tainted?
|
28
|
+
tmpdir = '/tmp'
|
29
|
+
end
|
30
|
+
|
31
|
+
lock = nil
|
32
|
+
n = failure = 0
|
33
|
+
|
34
|
+
begin
|
35
|
+
Thread.critical = true
|
36
|
+
|
37
|
+
begin
|
38
|
+
tmpname = sprintf('%s/%s%d.%d', tmpdir, basename, $$, n)
|
39
|
+
lock = tmpname + '.lock'
|
40
|
+
n += 1
|
41
|
+
end while @@cleanlist.include?(tmpname) or
|
42
|
+
File.exist?(lock) or File.exist?(tmpname)
|
43
|
+
|
44
|
+
Dir.mkdir(lock)
|
45
|
+
rescue
|
46
|
+
failure += 1
|
47
|
+
retry if failure < MAX_TRY
|
48
|
+
raise "cannot generate tempfile `%s'" % tmpname
|
49
|
+
ensure
|
50
|
+
Thread.critical = false
|
51
|
+
end
|
52
|
+
|
53
|
+
@data = [tmpname]
|
54
|
+
@clean_proc = Tempfile.callback(@data)
|
55
|
+
ObjectSpace.define_finalizer(self, @clean_proc)
|
56
|
+
|
57
|
+
@tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL, 0600)
|
58
|
+
@tmpname = tmpname
|
59
|
+
@@cleanlist << @tmpname
|
60
|
+
@data[1] = @tmpfile
|
61
|
+
@data[2] = @@cleanlist
|
62
|
+
|
63
|
+
super(@tmpfile)
|
64
|
+
|
65
|
+
# Now we have all the File/IO methods defined, you must not
|
66
|
+
# carelessly put bare puts(), etc. after this.
|
67
|
+
|
68
|
+
Dir.rmdir(lock)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Opens or reopens the file with mode "r+".
|
72
|
+
def open
|
73
|
+
@tmpfile.close if @tmpfile
|
74
|
+
@tmpfile = File.open(@tmpname, 'r+')
|
75
|
+
@data[1] = @tmpfile
|
76
|
+
__setobj__(@tmpfile)
|
77
|
+
end
|
78
|
+
|
79
|
+
def _close # :nodoc:
|
80
|
+
@tmpfile.close if @tmpfile
|
81
|
+
@data[1] = @tmpfile = nil
|
82
|
+
end
|
83
|
+
protected :_close
|
84
|
+
|
85
|
+
# Closes the file. If the optional flag is true, unlinks the file
|
86
|
+
# after closing.
|
87
|
+
#
|
88
|
+
# If you don't explicitly unlink the temporary file, the removal
|
89
|
+
# will be delayed until the object is finalized.
|
90
|
+
def close(unlink_now=false)
|
91
|
+
if unlink_now
|
92
|
+
close!
|
93
|
+
else
|
94
|
+
_close
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Closes and unlinks the file.
|
99
|
+
def close!
|
100
|
+
_close
|
101
|
+
@clean_proc.call
|
102
|
+
ObjectSpace.undefine_finalizer(self)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Unlinks the file. On UNIX-like systems, it is often a good idea
|
106
|
+
# to unlink a temporary file immediately after creating and opening
|
107
|
+
# it, because it leaves other programs zero chance to access the
|
108
|
+
# file.
|
109
|
+
def unlink
|
110
|
+
# keep this order for thread safeness
|
111
|
+
File.unlink(@tmpname) if File.exist?(@tmpname)
|
112
|
+
@@cleanlist.delete(@tmpname) if @@cleanlist
|
113
|
+
end
|
114
|
+
alias delete unlink
|
115
|
+
|
116
|
+
if RUBY_VERSION > '1.8.0'
|
117
|
+
def __setobj__(obj)
|
118
|
+
@_dc_obj = obj
|
119
|
+
end
|
120
|
+
else
|
121
|
+
def __setobj__(obj)
|
122
|
+
@obj = obj
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Returns the full path name of the temporary file.
|
127
|
+
def path
|
128
|
+
@tmpname
|
129
|
+
end
|
130
|
+
|
131
|
+
# Returns the size of the temporary file. As a side effect, the IO
|
132
|
+
# buffer is flushed before determining the size.
|
133
|
+
def size
|
134
|
+
if @tmpfile
|
135
|
+
@tmpfile.flush
|
136
|
+
@tmpfile.stat.size
|
137
|
+
else
|
138
|
+
0
|
139
|
+
end
|
140
|
+
end
|
141
|
+
alias length size
|
142
|
+
|
143
|
+
class << self
|
144
|
+
def callback(data) # :nodoc:
|
145
|
+
pid = $$
|
146
|
+
lambda{
|
147
|
+
if pid == $$
|
148
|
+
path, tmpfile, cleanlist = *data
|
149
|
+
|
150
|
+
print "removing ", path, "..." if $DEBUG
|
151
|
+
|
152
|
+
tmpfile.close if tmpfile
|
153
|
+
|
154
|
+
# keep this order for thread safeness
|
155
|
+
File.unlink(path) if File.exist?(path)
|
156
|
+
cleanlist.delete(path) if cleanlist
|
157
|
+
|
158
|
+
print "done\n" if $DEBUG
|
159
|
+
end
|
160
|
+
}
|
161
|
+
end
|
162
|
+
|
163
|
+
# If no block is given, this is a synonym for new().
|
164
|
+
#
|
165
|
+
# If a block is given, it will be passed tempfile as an argument,
|
166
|
+
# and the tempfile will automatically be closed when the block
|
167
|
+
# terminates. In this case, open() returns nil.
|
168
|
+
def open(*args)
|
169
|
+
tempfile = new(*args)
|
170
|
+
|
171
|
+
if block_given?
|
172
|
+
begin
|
173
|
+
yield(tempfile)
|
174
|
+
ensure
|
175
|
+
tempfile.close
|
176
|
+
end
|
177
|
+
|
178
|
+
nil
|
179
|
+
else
|
180
|
+
tempfile
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
end # module BugFix
|
187
|
+
if __FILE__ == $0
|
188
|
+
# $DEBUG = true
|
189
|
+
f = Tempfile.new("foo")
|
190
|
+
f.print("foo\n")
|
191
|
+
f.close
|
192
|
+
f.open
|
193
|
+
p f.gets # => "foo\n"
|
194
|
+
f.close!
|
195
|
+
end
|