如何在mingw上编写带有修改时间的文件列表? [英] How to shell script a list of files with their modification time on mingw?

查看:22
本文介绍了如何在mingw上编写带有修改时间的文件列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

免责声明:存在此问题是因为 Unity3D 及其库问题.

Disclaimer: This question exists because of Unity3D and its library issue.

我尝试获取 当前 git-cache-meta.sh 并在 Windows 上使用它.它不起作用.

I've tried getting current git-cache-meta.sh and use it on windows. It doesn't work.

我得到的第一个错误是在这一行:

The first error I got was on this line:

$ find `git ls-files`
find: invalid predicate `-'

将其更改为原始 find $(git ls-files) 也不起作用(即两种语法都不好).

Changing it to the original find $(git ls-files) also doesn't work (i.e. both syntaxes are no good).

invalid predicate 肯定是由于一个名为 "boo - foo.bar" 的文件造成的.所以我尝试运行 find "$(git ls-files)".然后它变成了一个 非常丑陋的错误/错误.

The invalid predicate is certainly due to a file named such as "boo - foo.bar". And so I tried to run find "$(git ls-files)". Then it turned into a very ugly error/bug.

我想知道为什么命令替换(奇怪的$() 不适用于 mingw,但更重要的是:

I wish to know why command substitution (the weird $() doesn't work on mingw, but, more importantly:

我们如何才能使 git-cache-meta.shmingw?

How can we make git-cache-meta.sh work properly on mingw?

正如您在下面看到的,我实际上设法在没有该关键字的情况下回答了这个问题 -> 正确.所以我仍然希望有人能想出一个快速而干净的解决方案 <- 我开始使用这个脚本的原因.

As you can see below, I actually manage to answer this without that keyword -> properly. So I still hope someone might come up with a fast and clean solution <- reason why I'm using this script to begin with.

推荐答案

原始脚本以优雅而复杂的风格编写(可能比必要的还要多).我重写了它,去掉了大部分复杂性.我不知道 mingw 上哪个功能中断了,但这更有可能起作用:

The original script was written in an elegant and complex style (probably more so than necessary). I rewrote it with most of the complexity removed. I don't know which feature is breaking on mingw, but this is more likely to work:

GIT_CACHE_META_FILE=.git_cache_meta
case $@ in
    --store)
        git ls-files|while read file; do
            find "$file" ( -printf 'chown %U %p
' ) 
               ( -printf 'chgrp %G %p
' ) 
               ( -printf 'chmod %#m %p
' ) 
               ( -printf 'touch -c -d -m "%TY-%Tm-%Td %TH:%TM:%TS" "%p"
' )
        done | tee $GIT_CACHE_META_FILE
        ;;
    --apply)
        sh -e $GIT_CACHE_META_FILE
        ;;
    *)
        echo "Usage: $0 --store|--apply"; exit 1
        ;;
esac

唯一可能出错的是系统上的一个可执行文件不支持此处使用的所有选项.那将是:find、chown、chgrp、touch 和 chmod.

The only thing that's likely to go wrong is if one of the executables on your system doesn't support all the options than are used here. That would be: find, chown, chgrp, touch, and chmod.

这篇关于如何在mingw上编写带有修改时间的文件列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆