Github user eiri commented on a diff in the pull request:
https://github.com/apache/couchdb-couch/pull/141#discussion_r57881585
--- 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 --
I assume you know that just re:run does the very same thing - passes params
to BIF that either compiles regex and runs match or detects MP and runs the
match right away, so it is not about performance. And I doubt this particular
part of code is hard to understand. 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.
Are you agree with just substituting file path with `#` for those files and
be done with it?
---
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.
---