diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-08-24 20:58:25 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-08-24 20:58:25 +0000 |
commit | 09178fca7320ed4919b7c5e845598f9ad998d6d3 (patch) | |
tree | 6239d2783969d9fd10df1dadf02628e0d4f15b1a | |
parent | ef70b5de358a728caa105b91016433ad2e9eeece (diff) | |
download | dtas-09178fca7320ed4919b7c5e845598f9ad998d6d3.tar.gz |
Some effects may be easier to save/store with relative directory paths, so allow changing this at runtime.
-rw-r--r-- | lib/dtas/player.rb | 4 | ||||
-rw-r--r-- | lib/dtas/player/client_handler.rb | 11 | ||||
-rw-r--r-- | test/test_player_integration.rb | 21 |
3 files changed, 36 insertions, 0 deletions
diff --git a/lib/dtas/player.rb b/lib/dtas/player.rb index b26303c..e055fa5 100644 --- a/lib/dtas/player.rb +++ b/lib/dtas/player.rb @@ -180,6 +180,10 @@ class DTAS::Player io.emit("OK") when "source" source_handler(io, msg) + when "cd" + chdir_handler(io, msg) + when "pwd" + io.emit(Dir.pwd) end end diff --git a/lib/dtas/player/client_handler.rb b/lib/dtas/player/client_handler.rb index aabd1ab..b3c208d 100644 --- a/lib/dtas/player/client_handler.rb +++ b/lib/dtas/player/client_handler.rb @@ -449,4 +449,15 @@ module DTAS::Player::ClientHandler io.emit("ERR unknown source op") end end + + def chdir_handler(io, msg) + msg.size == 1 or return io.emit("ERR usage: cd DIRNAME") + begin + Dir.chdir(msg[0]) + rescue => e + return io.emit("ERR chdir: #{e.message}") + end + # echo(%W(cd msg[0])) # should we broadcast this? + io.emit("OK") + end end diff --git a/test/test_player_integration.rb b/test/test_player_integration.rb index f7b1306..4ce0752 100644 --- a/test/test_player_integration.rb +++ b/test/test_player_integration.rb @@ -196,4 +196,25 @@ class TestPlayerIntegration < Minitest::Unit::TestCase assert(system("cmp", dump.path, expect.path), "files don't match #{dump.path} != #{expect.path}") end + + def test_cd_pwd + s = client_socket + pwd = Dir.pwd + + s.preq("pwd") + assert_equal pwd, s.readpartial(6666) + + s.preq("cd /") + assert_equal "OK", s.readpartial(6) + + s.preq("pwd") + assert_equal "/", s.readpartial(6) + + s.preq("cd /this-better-be-totally-non-existent-on-any-system-#{rand}") + err = s.readpartial(666) + assert_match(%r{\AERR }, err, err) + + s.preq("pwd") + assert_equal "/", s.readpartial(6) + end end |