[BUG] Can't remove non-existant file

John Arbash Meinel john at arbash-meinel.com
Thu May 26 17:19:53 BST 2005


Aaron Bentley wrote:

> Hi again,
>
> If we apply the fix from my "half-constructed Branch" email, we still
> can't remove a non existant file.
>
> abentley at troll:~/bzrtools2$ bzr remove .be
> bzr: error: u'/home/abentley/bzrtools2/.be' does not exist
> ~  at /home/abentley/bzr.dev/bzrlib/branch.py:64 in find_branch_root()
> ~  see ~/.bzr.log for debug information
>
> This comes from the fact that you determine the branch root from the
> first parameter, not the cwd.

Actually, it generally calls os.path.realpath() which doesn't care if
the file exists or not. Or it at least calls os.path.abspath() which
also doesn't care.

The specific problem is actually that lines 63 & 64 just should not be
there:
    if not os.path.exists(f):
        raise BzrError('%r does not exist' % f)

It explicitly checks if a file exists, when really it should just wait
for the while True: loop to fail.

I don't think there is a problem to say find_branch_root() of a file
that doesn't exist, but may in the near future (recent past).

>
> My knee-jerk reaction is to do os.path.dirname() on the argument to
> find_branch_root.  That would fix this case, but what if I tried this:
> $ bzr remove .be/bugs
>
> Now neither the argument, nor its parent directory exists.  Greaaaat.

No need, just remove the spurious exception.

>
> So on the one hand, we could recursively scan up until we hit a parent
> directory that *does* exist.  But that can cause typos to have
> exceedingly weird results-- we can wind up in a versioned directory
> several levels higher.
>
> I think a possibly-sane approach would be to use tree-root of the cwd as
> a stop-directory for the scan.  But that would mean that you'd never be
> able to remove files in a different working tree from the cwd's tree.
> (Except children of the cwd).
>
I would like to be able to remove a file in a subdirectory of the
current working tree, for instance:

/project/
    .bzr/
    library-a/
       file-a.cpp

cd /project/library-a
bzr remove file-a.cpp

This should work. I don't really care about nested, or not inside a
working directory. For instance:

cd /
bzr remove /project/library-a/file-a.cpp

I don't think that needs to work.

I guess that would mean that find_branch_root would be on '.', not on
the supplied filename.

> I think this is all way too heuristic to have in the Branch constructor.
> ~  I'd be much happier to see factory functions/methods called
> init_branch and find_branch instead of the init_branch and find_branch
> constructor options.
>
> As a bonus, that would also solve the "half-constructed" issue.
>
> Aaron

John
=:->

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 253 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20050526/01c356af/attachment.pgp 


More information about the bazaar mailing list