gpt4 book ai didi

ruby - 您如何检查 Capistrano 中是否存在文件(在远程服务器上)?

转载 作者:数据小太阳 更新时间:2023-10-29 06:22:47 24 4
gpt4 key购买 nike

像我在 Googleverse 中看到的许多其他人一样,我成为了 File.exists? 陷阱的受害者,它当然会检查您的本地文件系统,而不是您要部署到的服务器。

我发现了一个使用 shell hack 的结果,例如:

if [[ -d #{shared_path}/images ]]; then ...

但这对我来说不太合适,除非它被很好地包装在 Ruby 方法中。

有没有人优雅地解决了这个问题?

最佳答案

在 Capistrano 3 中,您可以:

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

这很好,因为它将远程测试的结果返回给您的本地 ruby​​ 程序,您可以使用更简单的 shell 命令。

关于ruby - 您如何检查 Capistrano 中是否存在文件(在远程服务器上)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1661586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com