由于某些原因,当我使用scp
将文件从当前机器移动到使用ant
的服务器时,它总是忽略空目录。
<scp todir="ec2-user@xx.x.x.xxx:/var/www/html" keyfile="${basedir}..keysprod_default.pem" trust="true">
<fileset dir="${staging.dir}" />
</scp>
为什么会这样?
完整更新详细日志:
D:BUILDSCRIPTS>ant -v -f getcom.xml update
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Buildfile: D:BUILDSCRIPTSgetcom.xml
Detected Java version: 1.7 in: C:Program Files (x86)Javajdk1.7.0_02jre
Detected OS: Windows Server 2008 R2
parsing buildfile D:BUILDSCRIPTSgetcom.xml with URI = file:/D:/BUILD/SCRIPTS/getcom.xml
Project base dir set to: D:BUILDSCRIPTS
parsing buildfile jar:file:/C:/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml
with URI = jar:file:/C:/ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
[property] Loading D:BUILDSCRIPTSbuild.properties
Build sequence for target(s) `update' is [update]
Complete build sequence is [update, upload, cleanup, staging, export, init, ]
update:
[exec] Current OS is Windows Server 2008 R2
[exec] Executing 'C:\Program Files (x86)\subversion\bin\svn' with arguments:
[exec] 'update'
[exec] 'D:BUILDSCRIPTS.._STAGINGGETOM'
[exec] '--username'
[exec] 'uuuu'
[exec] '--password'
[exec] 'uuuu'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
[exec] Updating 'D:BUILD_STAGINGGETOM':
[exec] At revision 134.
[scp] Connecting to xx.0.0.100:22
[scp] done.
[scp] Connecting to xx.0.2.100:22
[scp] done.
BUILD SUCCESSFUL
Total time: 8 seconds
属性:
svn.repoBaseURL="https://uuu@uuuu.uuuu.com"
svn.username="uuuu"
svn.password="uuuu"
svn.bin=C://Program Files (x86)//subversion//bin//
MSBuildPath=C://WINDOWS//Microsoft.NET//Framework//v4.0.30319//MSBuild.exe
lib.path.ant-contrib=C:/ant/lib/ant-contrib-1.0b3.jar
请注意,文件夹名称已更改。
您必须想出一个变通方法。Ant实现scp的方式意味着总是跳过空目录。
要点是Scp类是这样做的:
DirectoryScanner scanner = set.getDirectoryScanner(getProject());
Directory root = new Directory(scanner.getBasedir());
String[] files = scanner.getIncludedFiles();
if (files.length != 0) {
...
}
换句话说,只有当目录至少包含一个文件时,它才会处理该目录。
你可能会考虑为Scp任务代码提供一个补丁,但这意味着要定制Ant构建。
想到的另外两种方法是
- 通过填充占位符文件(部署后可以删除)使目录不为空
- 在单独的步骤中创建空目录