rstyx 0.3.0 → 0.3.1

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/rstyx/server.rb CHANGED
@@ -36,7 +36,7 @@
36
36
  # Copyright:: Copyright (c) 2005-2007 Rafael R. Sevilla
37
37
  # License:: GNU Lesser General Public License
38
38
  #
39
- # $Id: server.rb 231 2007-08-10 08:43:57Z dido $
39
+ # $Id: server.rb 234 2007-08-14 11:17:13Z dido $
40
40
  #
41
41
  require 'thread'
42
42
  require 'monitor'
@@ -652,8 +652,9 @@ module RStyx
652
652
  rescue Exception => e
653
653
  # if there was a problem removing the file, ignore it
654
654
  end
655
- sf.remove_client(sfc)
656
655
  end
656
+ sf.remove_client(sfc)
657
+ @fids.delete(fid)
657
658
  end
658
659
  end
659
660
 
@@ -865,7 +866,7 @@ module RStyx
865
866
  class SFile < Monitor
866
867
 
867
868
  attr_reader :name, :uid, :gid, :muid, :mtime
868
- attr_accessor :permissions, :atime, :parent
869
+ attr_accessor :permissions, :atime, :parent, :version
869
870
 
870
871
  ##
871
872
  # Create a new file object with the given permissions.
@@ -921,6 +922,8 @@ module RStyx
921
922
  # The clients who have a connection to the file
922
923
  @clients = []
923
924
  @clients.extend(MonitorMixin)
925
+ # Change listeners
926
+ @changelisteners = []
924
927
  end
925
928
 
926
929
  ##
@@ -1121,7 +1124,7 @@ module RStyx
1121
1124
  # written to. It should return the number of bytes actually
1122
1125
  # "written".
1123
1126
  #
1124
- def write(client, offset, count, data, truncate)
1127
+ def write(client, offset, data, truncate)
1125
1128
  raise StyxException.new("Cannot write to this file")
1126
1129
  end
1127
1130
 
@@ -1184,12 +1187,25 @@ module RStyx
1184
1187
  def client_disconnected(cl)
1185
1188
  end
1186
1189
 
1190
+ def add_changelistener(&block)
1191
+ @changelisteners << block
1192
+ end
1193
+
1187
1194
  def contents_changed
1188
1195
  version_incr
1196
+ @changelisteners.each do |listener|
1197
+ listener.call(self)
1198
+ end
1189
1199
  end
1190
1200
 
1191
1201
  def version_incr
1192
- self.version = ((self.version + 1) & 0xffffffffffffffff)
1202
+ @version = ((@version + 1) & 0xffffffffffffffff)
1203
+ end
1204
+
1205
+ def reply_write(count, session)
1206
+ self.set_mtime(Time.now, session.user)
1207
+ self.contents_changed
1208
+ return(Message::Rwrite.new(:count => count))
1193
1209
  end
1194
1210
 
1195
1211
  def refresh
@@ -1293,11 +1309,38 @@ module RStyx
1293
1309
  class InMemoryFile < SFile
1294
1310
  attr_accessor :contents
1295
1311
 
1312
+ def initialize(name, argv={ :permissions => 0666, :apponly => false,
1313
+ :excl => false, :uid => ENV["USER"],
1314
+ :gid => ENV["GROUP"] })
1315
+ super(name, argv)
1316
+ @contentslock = Mutex.new
1317
+ end
1318
+
1296
1319
  def read(client, offset, count)
1297
1320
  data = @contents[offset..(offset+count)]
1298
1321
  data ||= ""
1299
1322
  return(Message::Rread.new(:data => data))
1300
1323
  end
1324
+
1325
+ def write(client, offset, data, truncate)
1326
+ @contentslock.synchronize do
1327
+ # First write to the file
1328
+ if @contents.nil?
1329
+ @contents = ""
1330
+ end
1331
+
1332
+ if offset > @contents.length
1333
+ raise StyxException.new("attempt to write past the end of the file")
1334
+ end
1335
+
1336
+ @contents[offset..(offset + data.length)] = data
1337
+ if (truncate)
1338
+ @contents = @contents[0..(offset+data.length)]
1339
+ end
1340
+ return(reply_write(data.length, client.session))
1341
+ end
1342
+ end
1343
+
1301
1344
  end
1302
1345
 
1303
1346
  end # module Server
data/lib/rstyx/version.rb CHANGED
@@ -20,7 +20,7 @@
20
20
  #
21
21
  # RStyx version code
22
22
  #
23
- # $Id: version.rb 232 2007-08-10 08:44:34Z dido $
23
+ # $Id: version.rb 235 2007-08-14 11:17:48Z dido $
24
24
  #
25
25
 
26
26
  module RStyx
@@ -28,7 +28,7 @@ module RStyx
28
28
 
29
29
  MAJOR = 0
30
30
  MINOR = 3
31
- TINY = 0
31
+ TINY = 1
32
32
 
33
33
  # The version of RStyx in use.
34
34
  STRING = [ MAJOR, MINOR, TINY ].join(".")
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: rstyx
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.0
7
- date: 2007-08-10 00:00:00 +08:00
6
+ version: 0.3.1
7
+ date: 2007-08-14 00:00:00 +08:00
8
8
  summary: RStyx is a Ruby implementation of the 9P2000/Styx distributed file protocol used on Plan 9 and Inferno.
9
9
  require_paths:
10
10
  - lib