svn 返回“无效的控制字符‘0x0d’”在路径“图标\015”中尝试添加 Mac 自定义图标文件时

发布于 2024-11-14 14:42:45 字数 451 浏览 2 评论 0原文

我有一个创建磁盘映像的项目,并希望为加载的卷使用自定义图标。我有一个 .VolumeIcon.icns 文件,看起来很棒,但为了让 Finder 使用它,我必须包含一个名为 Icon^M 的空文件(Icon\r ,图标)。我的自定义图标出现了,一切都很好。

除了。当我尝试将 Icon^M 文件签入我的 svn 存储库时,我得到:

svn: Invalid control character '0x0d' in path 'Icon\015'

Subversion 的文件名标准比 Mac 更严格,并且不允许回车。 svn 邮件列表上的一个旧线程讨论了这个问题,建议只使用 shell 脚本创建文件作为构建过程的一部分。我可以做到这一点,但我的构建过程现在非常简单,我不愿意让它变得更复杂。

有更优雅的解决方案吗?

I have a project that creates a disk image and would like to use a custom icon for the loaded volume. I have a .VolumeIcon.icns file that looks great, but to make Finder use it, I've had to include an empty file named Icon^M (Icon\r, Icon<cr>). My custom icon shows up and everything works great.

Except. When I try to check the Icon^M file into my svn repository I get:

svn: Invalid control character '0x0d' in path 'Icon\015'

Subversion has stricter filename standards than Mac and, reasonably, doesn't allow carriage returns. An old thread on the svn mailing list discussed this problem, and the recommendation was to just create the file with a shell script as part of the build process. I could do that, but my build process is very simple right now and I'm loath to make it more complex.

Is there a more elegant solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

旧城空念 2024-11-21 14:42:45

这个图标问题困扰了我一段时间。基本的解决方案基本上是完全忽略该文件,我拒绝这样做,因为我是一个视觉人士,喜欢浪费时间为我的项目创建很酷的图标。

注意:我已尽力确保其有效,但我不能保证它,因此请尝试使用您的数据副本。话虽如此,这就是我对这个问题的解决方案。

基本上我创建了 3 个脚本来解决 mac 图标问题。

  1. repoMacPrepare.sh
  2. repoMacRestore.sh
  3. gitAliasScript.sh

这三个脚本用于以 git 或 svn 可以接受和存储的格式添加 mac 图标。第一个脚本准备存储库,搜索目录中基于图标的文件以及文件中的自定义图标格式。然后将它们存储为 .jdIcnd 或 .jdIcnf (d 代表目录 f 代表文件夹)在各自的路径中。

第二个脚本允许它通过搜索 .jdIcnd 和 .jdIcnf 文件在 Mac 上恢复活力。

最后一个脚本展示了如何自动化该过程。我使用 git 的别名来引用 .bashrc 文件中的 gitAliasScript.sh 脚本。现在我切换到 git (我做的最好的事情),因此显示了 git 的脚本,但 svn 中的基础知识是相同的。我希望这可以帮助使用版本控制系统的 Mac 用户,他们不会在签入过程或签出过程中丢失图标。另请注意,那些不使用此脚本的人不会遇到问题,因为图标存储为带有点前缀的二进制文件,使它们不可见。哦是的...

文件:repoMacPrepare.sh

#! /bin/bash
#
# Author: Joshua Demori
# Email: [email protected]
#
# This script is used to prepare a repository
# to still record the Icons used on a mac for files or directories
#
# First
# DeRez Icon^M > .IconCntrlR
# (hit control-v then enter to get the carriage return vi)
# 
# Store in Repository
# then to bring back
# Rez -append IconCopy -o Icon
# # may need to set the Folders Icon Info
# SetFile -a C /Path/To/Custom/Folder/With/Icon/
# 
# if I need to SetFile the folder I can do this 2 ways
# a main file which has all this data at base of repository (bad)
# as it finds those files it does the folder below it
#
#

#=======================================================#
# Defines
readonly  VERSION=1.00

#=======================================================#
# Variables
varVerbose=false

#=======================================================#
# Functions
setupDirIcon () {
    DeRez "${file}"/Icon
 > "${file}"/.Icon.jdIcnd
if [ $varVerbose == true ]; then
    echo Adding Icon File: "$file"/.Icon.jdIcnd
fi
}


setupFileIcon () {
    base=`basename "$file"` 
    path=`dirname "$file"`  
    DeRez "$file" > "${path}"/."${base}".jdIcnf
if [ $varVerbose == true ]; then
    echo Adding Icon File: "$file"/."${base}".jdIcnf
fi
}

# cmd line functions
function funcOptionVersion {
    echo "Reposiotry Mac Icon Preperation Script Version: $VERSION"
    exit 0
}


function funcOptionHelp {
    name=`basename $0`
    echo $name Help Screen
    echo '-h help'
    echo '-v verbose'
    echo '-n version'
    echo ' '
    exit 0
}

function funcOptionVerbose {
    varVerbose=true
}


#=======================================================#
# process cmd line arguments
while getopts "vhn" optionName; do
case "$optionName" in
n) funcOptionVersion ;;
h) funcOptionHelp ;;
v) funcOptionVerbose ;;
[?]) printErrorHelpAndExit "$badOptionHelp";;
esac
done

#=======================================================#
#=======================================================#
# Start main portion of script

# ignore . .DS_Store .git folders and files
find . | grep -v ^.$ | grep -v .DS_Store | grep -v .git | grep -v .svn | while read file
do

# does this file have an icon attribute
GetFileInfo -a "$file" | grep C > /dev/null
if [ $? = 0 ]; then
    if [ -d "$file" ]; then
        setupDirIcon
    else
        setupFileIcon
    fi
fi # end if for icon test

done

# Remove Only the Icon file used by directories
echo Removing Icon File

if [ $varVerbose == true ]; then
    find . -name Icon
 -print -exec rm {} \;
else
    find . -name Icon
 -exec rm {} \;
fi

文件:repoMacRestore.sh

#! /bin/bash
#
# Author: Joshua Demori
# Email: [email protected]
#
# This Script complemnts xxxx by reversing the icons as derez to rez
# then setting the proper file attributes to view the icons
#
# First
# DeRez Icon^M > .IconCntrlR
# (hit control-v then enter to get the carriage return vi)
# 
# Store in Repository
# then to bring back
# Rez -append IconCopy -o Icon
# # may need to set the Folders Icon Info
# SetFile -a C /Path/To/Custom/Folder/With/Icon/
# 
# if I need to SetFile the folder I can do this 2 ways
# a main file which has all this data at base of repository (bad)
# as it finds those files it does the folder below it
#
#


#=======================================================#
# Defines
readonly  VERSION=1.00

#=======================================================#
# Variables
varVerbose=false

#=======================================================#
# Functions
# cmd line functions
function funcOptionVersion {
  echo "Repository Mac Icon Restore Script Version: $VERSION"
  exit 0
}


function funcOptionHelp {
  name=`basename $0`
  echo $name Help Screen
  echo '-h help'
  echo '-v verbose'
  echo '-n version'
    echo ' '
  exit 0
}

function funcOptionVerbose {
    varVerbose=true
}


#=======================================================#
# process cmd line arguments
while getopts "vhn" optionName; do
case "$optionName" in
n) funcOptionVersion ;;
h) funcOptionHelp ;;
v) funcOptionVerbose ;;
[?]) printErrorHelpAndExit "$badOptionHelp";;
esac
done


#=======================================================#
#=======================================================#
# Start main portion of script


#=======================================================#
# Go thourgh directories
find . -name *.jdIcnd |  while read file
do

# is it a dir - restore dir icon
echo "$file" | grep jdIcnd
if [ $? = 0 ]; then
    if [ $varVerbose == true ]; then
        echo Fixing Directory Icon: "$file"
    fi
    path=`dirname "$file"`  
    Rez "$file" -o "${path}"/Icon
    SetFile -a V "${path}"/Icon
    SetFile -a C "${path}"
fi

done

# Go thourgh files
# is it a file - restore file icon
find . -name *.jdIcnf |  while read file
do
echo "$file" | grep jdIcnf
if [ $? = 0 ]; then
    path=`dirname "$file"`
    base=`basename "$file"`
    origFileName=`echo "$base" | sed 's/\.jdIcnf//'`
    origFileName=`echo "${origFileName:1}"`
    fileWithPath="${path}"/"${origFileName}"
    if [ $varVerbose == true ]; then
        echo Restoring File Icon: "$path"
    fi
    #echo origFileName: "$origFileName"
    #echo filesWithPath: "$fileWithPath"
    Rez -append "$file" -o "$fileWithPath"
    SetFile -a C "$fileWithPath"
fi

done

gitAliasScript.sh

#! /bin/bash

found=false
args=("$@")
for var in "$@"
do
    x=`echo $var | grep -ic commit`
    if [ $x == 1 ]; then
        # prepare icons to be saved
        # add them to repository
        # at the end git is run
        repoMacPrepare.sh
        find . -name *.jdIcnd -exec git add {} \;
        find . -name *.jdIcnf -exec git add {} \;
        found=true
    fi
done

#runs git cmd here
cmdPart='git '
cmd=${cmdPart}${@}
$cmd

# finish by bringing back icons
# if commit was called
if [ $found == true ]; then
    repoMacRestore.sh
fi

exit 0

This problem with icons has bothered me for some time. The basic solution was basically to ignore the file completely, which I refused to do as I am a visual person and enjoy wasting my time creating cool icons for my projects.

Note: I did my best to make sure it works, but I can't guarantee it, so try on a copy of your data. With that said here was my solution to this issue.

Basically I created 3 scripts to address the mac icon\r issue.

  1. repoMacPrepare.sh
  2. repoMacRestore.sh
  3. gitAliasScript.sh

These three scripts are used to add mac Icons in a format that git or svn can accept and store. The first script prepares the repository searching for Icon based files in directories and custom icon formats within files. Then stores them as either .jdIcnd or .jdIcnf (d for directory f for folder) within their respective paths.

The second script allows it to be brought back to life on the mac by searching for .jdIcnd and .jdIcnf files.

The last script shows how to automate the process. I use an alias for git that references the gitAliasScript.sh script in my .bashrc file. Now I switched to git (best thing I did) so the script is shown for git but the basics are the same in svn. I hope this helps mac users using versioning systems who don't won't to lose their icons as part of a checkin process or checkout process. Also note that those not using this script won't have issues since the icons are stored as binary files with a dot prefix making them invisible. Oooh yeah...

file: repoMacPrepare.sh

#! /bin/bash
#
# Author: Joshua Demori
# Email: [email protected]
#
# This script is used to prepare a repository
# to still record the Icons used on a mac for files or directories
#
# First
# DeRez Icon^M > .IconCntrlR
# (hit control-v then enter to get the carriage return vi)
# 
# Store in Repository
# then to bring back
# Rez -append IconCopy -o Icon
# # may need to set the Folders Icon Info
# SetFile -a C /Path/To/Custom/Folder/With/Icon/
# 
# if I need to SetFile the folder I can do this 2 ways
# a main file which has all this data at base of repository (bad)
# as it finds those files it does the folder below it
#
#

#=======================================================#
# Defines
readonly  VERSION=1.00

#=======================================================#
# Variables
varVerbose=false

#=======================================================#
# Functions
setupDirIcon () {
    DeRez "${file}"/Icon
 > "${file}"/.Icon.jdIcnd
if [ $varVerbose == true ]; then
    echo Adding Icon File: "$file"/.Icon.jdIcnd
fi
}


setupFileIcon () {
    base=`basename "$file"` 
    path=`dirname "$file"`  
    DeRez "$file" > "${path}"/."${base}".jdIcnf
if [ $varVerbose == true ]; then
    echo Adding Icon File: "$file"/."${base}".jdIcnf
fi
}

# cmd line functions
function funcOptionVersion {
    echo "Reposiotry Mac Icon Preperation Script Version: $VERSION"
    exit 0
}


function funcOptionHelp {
    name=`basename $0`
    echo $name Help Screen
    echo '-h help'
    echo '-v verbose'
    echo '-n version'
    echo ' '
    exit 0
}

function funcOptionVerbose {
    varVerbose=true
}


#=======================================================#
# process cmd line arguments
while getopts "vhn" optionName; do
case "$optionName" in
n) funcOptionVersion ;;
h) funcOptionHelp ;;
v) funcOptionVerbose ;;
[?]) printErrorHelpAndExit "$badOptionHelp";;
esac
done

#=======================================================#
#=======================================================#
# Start main portion of script

# ignore . .DS_Store .git folders and files
find . | grep -v ^.$ | grep -v .DS_Store | grep -v .git | grep -v .svn | while read file
do

# does this file have an icon attribute
GetFileInfo -a "$file" | grep C > /dev/null
if [ $? = 0 ]; then
    if [ -d "$file" ]; then
        setupDirIcon
    else
        setupFileIcon
    fi
fi # end if for icon test

done

# Remove Only the Icon file used by directories
echo Removing Icon File

if [ $varVerbose == true ]; then
    find . -name Icon
 -print -exec rm {} \;
else
    find . -name Icon
 -exec rm {} \;
fi

file: repoMacRestore.sh

#! /bin/bash
#
# Author: Joshua Demori
# Email: [email protected]
#
# This Script complemnts xxxx by reversing the icons as derez to rez
# then setting the proper file attributes to view the icons
#
# First
# DeRez Icon^M > .IconCntrlR
# (hit control-v then enter to get the carriage return vi)
# 
# Store in Repository
# then to bring back
# Rez -append IconCopy -o Icon
# # may need to set the Folders Icon Info
# SetFile -a C /Path/To/Custom/Folder/With/Icon/
# 
# if I need to SetFile the folder I can do this 2 ways
# a main file which has all this data at base of repository (bad)
# as it finds those files it does the folder below it
#
#


#=======================================================#
# Defines
readonly  VERSION=1.00

#=======================================================#
# Variables
varVerbose=false

#=======================================================#
# Functions
# cmd line functions
function funcOptionVersion {
  echo "Repository Mac Icon Restore Script Version: $VERSION"
  exit 0
}


function funcOptionHelp {
  name=`basename $0`
  echo $name Help Screen
  echo '-h help'
  echo '-v verbose'
  echo '-n version'
    echo ' '
  exit 0
}

function funcOptionVerbose {
    varVerbose=true
}


#=======================================================#
# process cmd line arguments
while getopts "vhn" optionName; do
case "$optionName" in
n) funcOptionVersion ;;
h) funcOptionHelp ;;
v) funcOptionVerbose ;;
[?]) printErrorHelpAndExit "$badOptionHelp";;
esac
done


#=======================================================#
#=======================================================#
# Start main portion of script


#=======================================================#
# Go thourgh directories
find . -name *.jdIcnd |  while read file
do

# is it a dir - restore dir icon
echo "$file" | grep jdIcnd
if [ $? = 0 ]; then
    if [ $varVerbose == true ]; then
        echo Fixing Directory Icon: "$file"
    fi
    path=`dirname "$file"`  
    Rez "$file" -o "${path}"/Icon
    SetFile -a V "${path}"/Icon
    SetFile -a C "${path}"
fi

done

# Go thourgh files
# is it a file - restore file icon
find . -name *.jdIcnf |  while read file
do
echo "$file" | grep jdIcnf
if [ $? = 0 ]; then
    path=`dirname "$file"`
    base=`basename "$file"`
    origFileName=`echo "$base" | sed 's/\.jdIcnf//'`
    origFileName=`echo "${origFileName:1}"`
    fileWithPath="${path}"/"${origFileName}"
    if [ $varVerbose == true ]; then
        echo Restoring File Icon: "$path"
    fi
    #echo origFileName: "$origFileName"
    #echo filesWithPath: "$fileWithPath"
    Rez -append "$file" -o "$fileWithPath"
    SetFile -a C "$fileWithPath"
fi

done

gitAliasScript.sh

#! /bin/bash

found=false
args=("$@")
for var in "$@"
do
    x=`echo $var | grep -ic commit`
    if [ $x == 1 ]; then
        # prepare icons to be saved
        # add them to repository
        # at the end git is run
        repoMacPrepare.sh
        find . -name *.jdIcnd -exec git add {} \;
        find . -name *.jdIcnf -exec git add {} \;
        found=true
    fi
done

#runs git cmd here
cmdPart='git '
cmd=${cmdPart}${@}
$cmd

# finish by bringing back icons
# if commit was called
if [ $found == true ]; then
    repoMacRestore.sh
fi

exit 0
小霸王臭丫头 2024-11-21 14:42:45

我觉得你骨头都秃了你现在用什么来构建?我向任何能够提出比您自己提出的答案更好的答案的人致敬 - 在构建中编写脚本。

I think you're boned. What are you using to build now? I'll tip my hat to anyone that can come up with a better answer than the one you yourself proposed - scripting it in the build.

木森分化 2024-11-21 14:42:45

我猜想将文件放入诸如 tar 之类的存档中将允许您上传它。
让我看看它是否真的有效......看起来我是对的:

$ touch  hello^Mhaha
$ svn add hello^Mhaha 
svn: Invalid control character '0x0d' in path 'hello\015haha'
$ tar cf hellorhaha.tar hello^Mhaha 
$ svn add hellorhaha.tar 
A  (bin)  hellorhaha.tar

也许不是你正在寻找的,但让你几乎不费力地添加文件。无论如何我都会这样做。实际上我不会在我的文件名中添加换行符或回车符,但是嘿..每个人都有自己的。

I'm guessing putting the file in an archive such as tar would allow you to upload it.
Let me see if it actually works... looks like I'm right:

$ touch  hello^Mhaha
$ svn add hello^Mhaha 
svn: Invalid control character '0x0d' in path 'hello\015haha'
$ tar cf hellorhaha.tar hello^Mhaha 
$ svn add hellorhaha.tar 
A  (bin)  hellorhaha.tar

Perhaps not what you're looking, but lets you add the file with almost no hustle. I would do it like that anyway. Actually I wouldn't put newlines or carriage returns in my file names, but hey.. to each his own.

傾旎 2024-11-21 14:42:45

这种情况发生在我身上,因为在我将图标文件重命名为 Icon.png 后,存在没有扩展名的图标文件(在本例中为 .png),一切都正常:)

This happens to me because there was icon file without extension (in this case .png) after I renamed the icon file to Icon.png it was all okay :)

请爱~陌生人 2024-11-21 14:42:45

复制 ~/.subversion/config
然后编辑 ~/.subversion/config ,首先找到如下所示的行:

全局忽略 = *.o *.lo *.la *.al .libs *.so .so.[0-9] *.a *.pyc *.pyo

然后添加 a配置中的新行:

全局忽略 = 图标?

保存配置文件。这将忽略名称以“Icon”加一个附加字符开头的所有文件。

不如忽略完全忽略该文件的名称。但它的工作原理需要注意。

Make a copy of ~/.subversion/config
Then edit ~/.subversion/config by first finding the line which looks like:

global-ignores = *.o *.lo *.la *.al .libs *.so .so.[0-9] *.a *.pyc *.pyo

Then add after that a new line in config:

global-ignores = Icon?

Save the config file. This will ignore all files whose name starts with "Icon" plus one additional character.

Not as good as ignore ignoring exactly what that file is named. But it works with caveat.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文