Edgewall Software
Modify

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#12000 closed defect (fixed)

Symbolic link for trac.ini overwritten when saving Configuration object

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: normal Milestone: 1.0.6
Component: general Version:
Severity: normal Keywords: config
Cc:
Release Notes:

Fixed: symbolic link at conf/trac.ini overwritten on configuration save.

API Changes:

AtomicFile supports symbolic link as the path argument.

Description (last modified by Ryan J Ollos)

I tried storing trac.ini in a version-controlled directory outside of the Environment, using a symbolic link in the Environment conf directory. The symbolic link is not followed when saving the Configuration object.

Using os.path.realpath seems to be the proper solution:

user@ubuntu:~/Workspace$ touch file
user@ubuntu:~/Workspace$ ln -s file link
user@ubuntu:~/Workspace$ ls -al file link
-rw-rw-r-- 1 user user 0 Mar 25 21:17 file
lrwxrwxrwx 1 user user 4 Mar 25 21:17 link -> file
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.realpath('/home/user/Workspace/link')
'/home/user/Workspace/file'

The following patch appears to work.

  • trac/config.py

    diff --git a/trac/config.py b/trac/config.py
    index d407da1..43ecd81 100644
    a b class Configuration(object):  
    129129    when the file has changed.
    130130    """
    131131    def __init__(self, filename, params={}):
    132         self.filename = filename
     132        self.filename = os.path.realpath(filename)  # follow any symlinks
    133133        self.parser = UnicodeParser()
    134134        self._parsed_sections = {}
    135135        self.parents = []

Inherited files and files defined in PathOptions are resolved relative to the location of trac.ini. Before the patch this is always the Environment conf directory. I think the behaviour is better after the patch.

Attachments (0)

Change History (5)

comment:1 Changed 4 years ago by Jun Omae

Configuration.filename instance is used with os.path.dirname() in Seciotn.getpath() at tags/trac-1.0.5/trac/config.py@:481#L471. Applying the patch would change behavior of PathOption, e.g. when $ENV/conf is a symbolic link.

I consider the root cause is that AtomicFile.commit() removes a symbolic file. We should modify AtomicFile class.

  • trac/util/__init__.py

    diff --git a/trac/util/__init__.py b/trac/util/__init__.py
    index 0419411..5161afc 100644
    a b class AtomicFile(object):  
    170170    the temporary file is removed.
    171171    """
    172172    def __init__(self, path, mode='w', bufsize=-1):
     173        path = os.path.realpath(path)
    173174        self._file = None
    174175        self._path = path
    175176        (dir, name) = os.path.split(path)

comment:2 in reply to:  description Changed 4 years ago by Ryan J Ollos

Replying to rjollos:

Inherited files and files defined in PathOptions are resolved relative to the location of trac.ini. Before the patch this is always the Environment conf directory. I think the behaviour is better after the patch.

I've reconsidered based on comment:1. It will probably be better to store all files relative to the conf directory, rather than relative to trac.ini. We can just symlink all files in conf, if desired.

Proposed changes in log:rjollos.git:t12000. Tested on Ubuntu 14.04 and Windows 7.

comment:3 Changed 4 years ago by Ryan J Ollos

API Changes: modified (diff)
Owner: set to Ryan J Ollos
Release Notes: modified (diff)
Status: newassigned

comment:4 Changed 4 years ago by Ryan J Ollos

Resolution: fixed
Status: assignedclosed

Committed to 1.0-stable in [13934], merged to trunk in [13935].

comment:5 Changed 4 years ago by Ryan J Ollos

Description: modified (diff)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.