如何仅在Makefile中最近发生更改时下载文件
我通常使用如何仅在Makefile中最近发生更改时下载文件,makefile,Makefile,我通常使用wget下载Makefile中的文件,例如: myu文件: wgethttp://myserver/$@-O$@.tmp和&mv$@.tmp$@ 我首先在一个tmp文件中下载:如果传输被中断,当重新启动Makefile时,该文件将被正确地重新下载 问题是,使用-O选项,仅当远程文件比本地文件更新时,才可能使用-N选项来获取文件 我的问题是:在Makefile中,只有在远程文件较新时才下载文件,并且对传输中断具有鲁棒性的最佳方式是什么?我通过使用cURL而不是wget解决了我的问题。我
wget
下载Makefile中的文件,例如:
myu文件:
wgethttp://myserver/$@-O$@.tmp和&mv$@.tmp$@
我首先在一个tmp文件中下载:如果传输被中断,当重新启动Makefile时,该文件将被正确地重新下载
问题是,使用-O
选项,仅当远程文件比本地文件更新时,才可能使用-N
选项来获取文件
我的问题是:在Makefile中,只有在远程文件较新时才下载文件,并且对传输中断具有鲁棒性的最佳方式是什么?我通过使用
cURL
而不是wget
解决了我的问题。我的Makefile目标变成:
my_file:
curl -s -S -L -f http://myserver/$@ -z $@ -o $@.tmp && mv -f $@.tmp $@ 2>/dev/null || rm -f $@.tmp $@
说明:
-s: silent, no progress bar displayed
-S: if silent, shows error message on fail
-L: in case of redirection, follow it and redo the request; this is necessary to correctly get modification date
-f: in case of error do not display the document returned
-z my_local_file: download remote file only if last modification date more recent that modification date of 'my_local_file'
-o filename: store downloaded file into 'filename'
- 成功后,将临时文件移动到最终位置(
)&&mv-f$@.tmp$@
- 如果文件未重新下载,则将
的stderr重定向到mv
,以便临时文件不存在(/dev/null
)&mv-f$@.tmp$@2>/dev/null
- 如果出现错误,
temp文件和最终文件(rm
)|rm-f$@.tmp$@
wget
可以管理它认为合适的原始文件名?那么,在这种情况下,目标文件和远程文件的名称应该不同,这很麻烦。