How can you check to see if a file exists (on the remote server) in Capistrano?

前端 未结 5 895
忘了有多久
忘了有多久 2020-12-24 01:14

Like many others I\'ve seen in the Googleverse, I fell victim to the File.exists? trap, which of course checks your local file system, not the server y

5条回答
  •  清歌不尽
    2020-12-24 01:50

    In capistrano 3, you can do:

    on roles(:all) do
      if test("[ -f /path/to/my/file ]")
        # the file exists
      else
        # the file does not exist
      end
    end
    

    This is nice because it returns the result of the remote test back to your local ruby program and you can work in simpler shell commands.

提交回复
热议问题