03-save-data-per-user.diff 存在的若干问题

Bug #1161425 reported by Xu Zhen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Chinese-calendar
Fix Released
High
Abel Liu

Bug Description

chinese-calendar 0.7.6-0ubuntu4中的03-save-data-per-user.diff 存在以下问题:

1、获取用户家目录的方式

现在的做法是从环境变量中取得用户名,再判断是否是root,再选择/root/.chinese-calendar或/home/用户名/.chinese-calendar作为存放数据库的目录

这么做有个大问题,用户家目录实际上是在/etc/passwd中指定,非root用户不见得就是/home/用户名/。而且,从环境变量中取得数据的方法也大有问题。environment.filter("USER").at(0).split("=").at(1),如果用户有其他包含"USER"字串的环境变量(甚至只要变量值中含有USER),就可能导致取得错误的目录

2、数据库文件存放的目录

放到家目录下".程序名"的做法已经是不被推荐的了。根据Linux Standard Base Desktop Specification中Base Directory Spec一节的要求,应该按照XDG Base Directory Specification(http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html),将数据放到$XDG_DATA_HOME(默认$HOME/.local/share),配置放到 $XDG_CONFIG_HOME(默认$HOME/.config)

3、复制数据库的问题

现在是通过system()来调用shell执行mkdir和cp,完全没必要额外开三个进程,而且还无法得知创建目录/复制文件是否成功。而且最后还用cmd.toAscii(),这样就无法应对路径中含有非ascii字符的情况

==========================

我另外写了个03-save-data-per-user.patch,针对以上问题做了修改:
1&2、直接用内建的QDesktopServices类来获取数据目录,用这种方法取得的目录应该是$HOME/.local/share/data
3、用QDir和QFile提供的方法来创建目录/复制文件

Revision history for this message
Xu Zhen (xuzhen666) wrote :
description: updated
Revision history for this message
Xu Zhen (xuzhen666) wrote :

对了,QDesktopServices::storageLocation方法是2008年发布的Qt 4.4引入的,如果有意支持更早版本的Qt库,或者要放到$HOME/.local/share或$HOME/.config下,可以用以下的方法

    QStringList env = QProcess::systemEnvironment().filter(QRegExp("^XDG_DATA_HOME="));
    if (env.length() == 0) {
        systemdirectory = QDir::homePath() + "/.local/share";
    } else {
        systemdirectory = env.at(0);
        systemdirectory = systemdirectory.mid(systemdirectory.indexOf("=") + 1);
        if (systemdirectory.isEmpty()) {
            systemdirectory = QDir::homePath() + "/.local/share";
        }
    }

Revision history for this message
Jack Yu (jackyu) wrote :

Wow, thank you. We will go through your patch asap.

Jack Yu (jackyu)
Changed in chinese-calendar:
importance: Undecided → High
assignee: nobody → Abel Liu (guiltyritter)
Abel Liu (guiltyritter)
Changed in chinese-calendar:
status: New → In Progress
Abel Liu (guiltyritter)
Changed in chinese-calendar:
milestone: none → 0.7.6
Abel Liu (guiltyritter)
Changed in chinese-calendar:
status: In Progress → Fix Committed
Abel Liu (guiltyritter)
Changed in chinese-calendar:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.