[Sugar-devel] [PATCH] Copying files multiple times results in bogus names. (SL#2060)

James Cameron quozl at laptop.org
Wed Nov 10 18:15:11 EST 2010


On Wed, Nov 10, 2010 at 05:24:11PM +0530, shanjit at seeta.in wrote:
> From: Shanjit Singh Jajmann <shanjit at seeta.in>
> 
> For every existing file copied to the location, the names are
> explicitly changed to filename(copynumber). e.g. games.png,
> games(2).png. games(3).jpg and so on.

Nak.

1.  it doesn't meet the expected naming scheme agreed on in the ticket,
"foo, foo_1, foo_2, foo_3".

2.  it adds parentheses to the file name, which are unnecessary,

3.  it starts at _2 rather than _1 (i = 2)

I'm glad to say though that the idea of taking the splitext call out of
the while loop is indeed the key to the solution.

> --- a/src/jarabe/journal/model.py
> +++ b/src/jarabe/journal/model.py
> @@ -528,10 +528,10 @@ def _get_file_name(title, mime_type):
>  
>  def _get_unique_file_name(mount_point, file_name):
>      if os.path.exists(os.path.join(mount_point, file_name)):
> -        i = 1
> +        i = 2
> +        name, extension = os.path.splitext(file_name)
>          while len(file_name) <= 255:
> -            name, extension = os.path.splitext(file_name)
> -            file_name = name + '_' + str(i) + extension
> +            file_name = name + '(' + str(i) + ')' + extension
>              if not os.path.exists(os.path.join(mount_point, file_name)):
>                  break
>              i += 1

-- 
James Cameron
http://quozl.linux.org.au/


More information about the Sugar-devel mailing list