/stdhome

To get this branch, use:
bzr branch http://bzr.ed.am/stdhome

« back to all changes in this revision

Viewing changes to lib/stdhome/command/add.py

  • Committer: Tim Marston
  • Date: 2016-12-13 21:40:34 UTC
  • Revision ID: tim@ed.am-20161213214034-nd5t7ztnlrjd627i
fix add command and generic filename expansion/resolution to expend to
homedir-relative filename and absolute filename based on original filename, as
specified, rather than a fully, symlink-resolved filename.  So, e.g., if ~/bob
was a symlink to ~/fred, then ~/bob/a would resolve to the relative filename
bob/a, becuase it is inside the homedir (it would resolve to fred/a otherwise)

Show diffs side-by-side

added added

removed removed

115
115
 
116
116
 
117
117
 
118
 
 
119
118
        @staticmethod
120
119
        def expand_home_files( files, recurse ):
121
120
                """Returns a unique, sorted list of relative filenames, calculated from the list
122
121
                provided, which is made up from individual files and directories
123
 
                relative to the CWD.  Directories are recursed in to as requried, and
124
 
                leading path components of any items are alse returned.  Specified
125
 
                filenames must exist in the home directory (although they may not exist
126
 
                in the repo).
 
122
                relative to the CWD.  As directories are found, they may optionally be
 
123
                recursed in to.  Leading path components of any items are alse returned.
 
124
                Specified filenames must exist in the home directory (although they do
 
125
                not have to exist in the repo).
127
126
 
128
127
                This is a modified version of command.expand_files().
129
128
 
134
133
 
135
134
                # iterate through file list
136
135
                for file in files:
137
 
                        parts = os.path.split( file )
138
 
                        abs_file = os.path.join(
139
 
                                os.path.realpath( parts[ 0 ] ), parts[ 1 ] )
140
 
 
141
 
                        # check the file is in the home directory
142
 
                        if abs_file[ : len( home_dir_prefix ) ] != home_dir_prefix:
143
 
                                raise the.program.FatalError(
144
 
                                        'not under home directory: %s' % abs_file )
145
 
 
146
 
                        # relative file
147
 
                        rel_file = abs_file[ len( home_dir_prefix ) : ]
148
 
 
149
 
                        # check if file exists in home directory
150
 
                        if not os.path.lexists( abs_file ):
151
 
                                raise the.program.FatalError(
152
 
                                        'not found in home directory: %s' % rel_file )
 
136
                        ( rel_file, abs_file ) = Command.resolve_homedir_file( file )
 
137
 
 
138
                        # check that file exists in homedir
 
139
                        if not os.path.exists( abs_file ):
 
140
                                raise the.program.FatalError(
 
141
                                        'not found in home directory: %s' % file )
153
142
 
154
143
                        # ensure parent path parts are included
155
144
                        path = rel_file