Github user iilyak commented on a diff in the pull request:

    https://github.com/apache/couchdb-couch/pull/141#discussion_r57929735
  
    --- Diff: src/couch_file.erl ---
    @@ -218,24 +218,63 @@ close(Fd) ->
         gen_server:call(Fd, close, infinity).
     
     
    -delete(RootDir, Filepath) ->
    -    delete(RootDir, Filepath, true).
    -
    -
    -delete(RootDir, Filepath, Async) ->
    -    DelFile = filename:join([RootDir,".delete", 
?b2l(couch_uuids:random())]),
    +delete(RootDir, Filepath, Options) ->
    +    Async = not lists:member(sync, Options),
    +    Strategy = couch_util:get_value(strategy, Options, delete),
    +    DelFile = deleted_filename(RootDir, Filepath, Strategy),
         case file:rename(Filepath, DelFile) of
    -    ok ->
    -        if (Async) ->
    -            spawn(file, delete, [DelFile]),
    -            ok;
    -        true ->
    -            file:delete(DelFile)
    -        end;
    -    Error ->
    -        Error
    +        ok when Strategy /= delete ->
    +            Now = calendar:local_time(),
    +            case file:change_time(DelFile, Now) of
    +                ok -> {ok, {renamed, DelFile}};
    +                Else -> Else
    +            end;
    +        ok when Async ->
    +            spawn(fun() -> delete_file(DelFile) end),
    +            {ok, deleted};
    +        ok ->
    +            delete_file(DelFile);
    +        Error ->
    +            Error
    +    end.
    +
    +delete_file(FilePath) ->
    +    case file:delete(FilePath) of
    +        ok -> {ok, deleted};
    +        Else -> Else
         end.
     
    +deleted_filename(_RootDir, Original, rename) ->
    +    deleted_filename(Original, "deleted");
    +deleted_filename(RootDir, Original, _Strategy) ->
    +    DelFileName = deleted_filename_base(RootDir, Original),
    +    DelFile = filename:join([RootDir,".delete", DelFileName]),
    +    Ending = io_lib:format("~6s", [couch_uuids:random()]),
    +    deleted_filename(DelFile, Ending).
    +
    +deleted_filename(Original, Ending) ->
    +    RootName = filename:rootname(Original),
    +    Suffix = deleted_filename_suffix(),
    +    Extention = filename:extension(Original),
    +    io_lib:format("~s.~s.~s~s", [RootName, Suffix, Ending, Extention]).
    +
    +deleted_filename_base(RootDir, FullPath) ->
    +    Shard = "\\.?shards/([0-9a-f]{8}-[0-9a-f]{8})",
    +    User = "\\.?(.+)",
    +    ViewFile = "(?:mrview/(.+\\.view))",
    +    DbFile = "(.+\\.couch.*)",
    +    Pattern = "^~s(?:/~s)?(?:/~s)?(?:/(?:~s|~s))$",
    +    RegExp =  io_lib:format(Pattern, [RootDir, Shard, User, ViewFile, 
DbFile]),
    +    {ok, MP} = re:compile(RegExp),
    --- End diff --
    
    > so it is not about performance. 
    
    It is not about performance. Sorry I was not clear enough. I just wanted to 
mention that the `re:compile` line is not needed in this case.
    
    > So I should admit I don't really get what is your rational on rejecting 
this change now, but given it's a third implementation I'm doing I don't really 
care anymore.
    
    I'm sorry for being such a jerk. I didn't meant to. 
    
    > Are you agree with just substituting file path with # for those files and 
be done with it?
    
    Either `#` or urlencode as @kxepal proposed. As a primary mechanism (not as 
a fallback). It would simplify implementation a lot.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to