Patch

如何從任何工作目錄應用 -p0 更新檔?

  • March 3, 2020

我有一個我希望使用的絕對路徑更新檔。即前幾行如下。

--- /usr/share/apps/plasma/packages/org.kde.pager/contents/ui/main.qml  2014-10-10 18:47:23.000000000 +1100
+++ /usr/share/apps/plasma/packages/org.kde.pager/contents/ui/main.qml.mod  2014-11-11 09:44:17.786200477 +1100

但是,除非我在根目錄中,否則它會失敗。

~$ cd
~$ sudo patch -i /tmp/fix_kde_icons.patch -p0
Ignoring potentially dangerous file name /usr/share/apps/plasma/packages/org.kde.pager/contents/ui/main.qml
Ignoring potentially dangerous file name /usr/share/apps/plasma/packages/org.kde.pager/contents/ui/main.qml.mod
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
...
~$ cd /tmp
/tmp$ sudo patch -i /tmp/fix_kde_icons.patch -p0
... #same error as above
/tmp$ cd /usr
/usr$ sudo patch -i /tmp/fix_kde_icons.patch -p0
... #same error as above
/usr$ cd /
/$ sudo patch -i /tmp/fix_kde_icons.patch -p0
patching file /usr/share/apps/plasma/packages/org.kde.pager/contents/ui/main.qml

有沒有辦法在patch任何工作目錄中使用絕對路徑?

查看 GNU 更新檔的原始碼,這種行為是從 2.7 版開始內置的。從 GNU 更新檔 2.7.1 開始,只..接受不包含的相對路徑,除非目前目錄是根目錄。

要應用包含絕對路徑的更新檔,您可以使用

(cd / && sudo patch -p0) <foo.patch

在最新版本的 GNU 更新檔中,您可以簡單地

sudo patch -d/ -p0 <foo.patch

至少使用 GNU 更新檔 2.7.6,可以指定文件名:

patch /usr/share/apps/plasma/packages/org.kde.pager/contents/ui/main.qml /tmp/fix_kde_icons.patch

引用自:https://unix.stackexchange.com/questions/167216