Anonymous avatar Anonymous committed 76879ad

make sure ring files were found in the ring directory, before choosing one

this makes it safe to put the embedded node under a VCS that puts dotfiles in subdirectories

Comments (0)

Files changed (1)

apps/riak/src/riak_ring_manager.erl

                     Timestamps = [TS || {"riak_ring", C1, TS} <- 
                      [list_to_tuple(string:tokens(FN, ".")) || FN <- Filenames],
                                         C1 =:= Cluster],
-                    TSPat = [io_lib:fread("~4d~2d~2d~2d~2d~2d",TS) ||
-                                TS <- Timestamps],
-                    TSL = lists:reverse(lists:sort([TS ||
-                                                       {ok,TS,[]} <- TSPat])),
-                    Keep = prune_list(TSL),
-                    KeepTSs = [lists:flatten(
-                         io_lib:format(
-                           "~B~2.10.0B~2.10.0B~2.10.0B~2.10.0B~2.10.0B",K))
-                               || K <- Keep],
-                    DelFNs = [Dir ++ "/" ++ FN || FN <- Filenames, 
-                                                  lists:all(fun(TS) -> 
-                                                      string:str(FN,TS)=:=0
-                                                            end, KeepTSs)],
-                    riak_eventer:notify(riak_ring_manager, prune_ringfiles,
-                                        {length(DelFNs),length(Timestamps)}),
-                    [file:delete(DelFN) || DelFN <- DelFNs],
-                    ok
+                    if Timestamps /= [] ->
+                            %% there are existing ring files
+                            TSPat = [io_lib:fread("~4d~2d~2d~2d~2d~2d",TS) ||
+                                        TS <- Timestamps],
+                            TSL = lists:reverse(lists:sort([TS ||
+                                                               {ok,TS,[]} <- TSPat])),
+                            Keep = prune_list(TSL),
+                            KeepTSs = [lists:flatten(
+                                         io_lib:format(
+                                           "~B~2.10.0B~2.10.0B~2.10.0B~2.10.0B~2.10.0B",K))
+                                       || K <- Keep],
+                            DelFNs = [Dir ++ "/" ++ FN || FN <- Filenames, 
+                                                          lists:all(fun(TS) -> 
+                                                                            string:str(FN,TS)=:=0
+                                                                    end, KeepTSs)],
+                            riak_eventer:notify(riak_ring_manager, prune_ringfiles,
+                                                {length(DelFNs),length(Timestamps)}),
+                            [file:delete(DelFN) || DelFN <- DelFNs],
+                            ok;
+                       true ->
+                            %% directory wasn't empty, but there are no ring
+                            %% files in it
+                            ok
+                    end
             end
     end.
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.