Commit ab2b7fd2dc048f7df007cc02e4a46d9f770036b3

Thomas de Grivel 2022-01-17T15:43:06

factorize disk usage, use :kb

diff --git a/lib/kmxgit/git_manager.ex b/lib/kmxgit/git_manager.ex
index 0e75a63..05c5798 100644
--- a/lib/kmxgit/git_manager.ex
+++ b/lib/kmxgit/git_manager.ex
@@ -283,7 +283,7 @@ defmodule Kmxgit.GitManager do
 
   def disk_usage(repo) do
     dir = git_dir(repo)
-    {out, status} = System.cmd("du", ["-ms", dir], stderr_to_stdout: true)
+    {out, status} = System.cmd("du", ["-ks", dir], stderr_to_stdout: true)
     case status do
       0 -> {:ok, Integer.parse(out)}
       _ -> {:error, out}
diff --git a/lib/kmxgit_web.ex b/lib/kmxgit_web.ex
index a562e56..ac2e890 100644
--- a/lib/kmxgit_web.ex
+++ b/lib/kmxgit_web.ex
@@ -60,6 +60,12 @@ defmodule KmxgitWeb do
       def recaptcha_site_key do
         Application.get_env :kmxgit, :recaptcha_site_key
       end
+
+      def disk_usage(size) do
+        FileSize.new(size, :kb)
+        |> FileSize.convert(:mb)
+        |> FileSize.to_string()
+      end
     end
   end
 
diff --git a/lib/kmxgit_web/templates/organisation/show.html.heex b/lib/kmxgit_web/templates/organisation/show.html.heex
index 28fcbd9..891a362 100644
--- a/lib/kmxgit_web/templates/organisation/show.html.heex
+++ b/lib/kmxgit_web/templates/organisation/show.html.heex
@@ -72,7 +72,7 @@
         </tr>
         <tr>
           <th><%= gettext("Disk usage") %></th>
-          <td><%= FileSize.new(@disk_usage, :mb) |> FileSize.to_string() %></td>
+          <td><%= disk_usage(@disk_usage) %></td>
         </tr>
       </table>
     </div>
diff --git a/lib/kmxgit_web/templates/page/index.html.heex b/lib/kmxgit_web/templates/page/index.html.heex
index 445bd30..18f946c 100644
--- a/lib/kmxgit_web/templates/page/index.html.heex
+++ b/lib/kmxgit_web/templates/page/index.html.heex
@@ -1,7 +1,7 @@
 <div class="container-fluid">
   <p>
     <code>
-      "Hello, world !"
+      "<%= gettext "Hello, world !" %>"
     </code>
   </p>
   <p>
@@ -13,6 +13,6 @@
     <%= gettext "You can register and create public and private Git repositories." %>
   </p>
 
-  <h3>SSH keys fingerprint</h3>
+  <h3><%= gettext "SSH keys fingerprint" %></h3>
   <pre><%= render("ssh_keys_fingerprint.txt") %></pre>
 </div>
diff --git a/lib/kmxgit_web/templates/repository/show_properties.html.heex b/lib/kmxgit_web/templates/repository/show_properties.html.heex
index baff4be..d3bf8c3 100644
--- a/lib/kmxgit_web/templates/repository/show_properties.html.heex
+++ b/lib/kmxgit_web/templates/repository/show_properties.html.heex
@@ -66,6 +66,6 @@
   <% end %>
   <tr>
     <th><%= gettext("Disk usage") %></th>
-    <td><%= FileSize.new(@disk_usage, :mb) |> FileSize.to_string() %></td>
+    <td><%= disk_usage(@disk_usage) %></td>
   </tr>
 </table>
diff --git a/lib/kmxgit_web/templates/user/show.html.heex b/lib/kmxgit_web/templates/user/show.html.heex
index b0e4cd7..7fd1350 100644
--- a/lib/kmxgit_web/templates/user/show.html.heex
+++ b/lib/kmxgit_web/templates/user/show.html.heex
@@ -84,7 +84,7 @@
         </tr>
         <tr>
           <th><%= gettext("Disk usage") %></th>
-          <td><%= FileSize.new(@disk_usage, :mb) |> FileSize.to_string() %></td>
+          <td><%= disk_usage(@disk_usage) %></td>
 </tr>
       </table>
     </div>