From a1153b8ce8a72d4e2b7c506c1571f3d98687cd3f Mon Sep 17 00:00:00 2001
From: Lukas Bulwahn <lukas.bulwahn@oss.bmw-carit.de>
Date: Mon, 2 Mar 2015 10:54:57 +0100
Subject: [PATCH] rosclean: simplifying run-time dependencies

When roslaunch is started, it checks the file size of the local log
directory by calling:

    disk_usage = rosclean.get_disk_usage(d) [1]

The function `get_disk_usage` [2] in rosclean creates a subprocess and
calls `du -sb` on Linux systems (cf. [3]).

However, the `du` command, which busybox usually provides on an
embedded Linux image, does not support the `-b` option, and only the
`du` command from the coreutils [4] supports this option.
This issue was first reported in April 2013 on the meta-ros issue
tracker [5]. Hence, on the first iteration of this issue, the
commit db0c8d5c [6] simply adds the dependency on coreutils to
roslaunch.

However, this has certain disadvantages:
  - coreutils is licensed under GPLv3 and must not be deployed in a
    product, which is massively distributed to customers.
  - coreutils has larger file-system foot print than busybox and makes
    the minimal Linux images considerably larger.

As a fortuitous circumstance, Alexis Ballier [7] had already observed
this disadvantage and provides a patch [8, 9] that makes
`get_disk_usage` use `du -k`, which works with busybox and coreutils.

So, on the second iteration of this issue, this commit here patches
rosclean's `get_disk_usage` function with the aforementioned patch.
This slightly modifies the semantics of this function. However, I
believe this plays only a minor role for the overall intended
functionality to check if the log usage has reached a critical file-size
limit, and it allows us to remove the dependency on coreutils, which is
much more critical.

Andreas Baak reported the disadvantages of the previous solution, which
triggered the re-investigation. The current resolution has been
discussed and worked out in collaboration with Andreas Baak.

[1] https://github.com/ros/ros_comm/blob/9da29441f32575deb90ee73c9602a5527aacc966/tools/roslaunch/src/roslaunch/rlutil.py#L63
[2] https://github.com/ros/ros/blob/c6e91f9af1410ef183cfa273a7395f896d2d2a1f/tools/rosclean/src/rosclean/__init__.py#L120
[3] https://github.com/ros/ros/blob/c6e91f9af1410ef183cfa273a7395f896d2d2a1f/tools/rosclean/src/rosclean/__init__.py#L130
[4] http://cgit.openembedded.org/cgit.cgi/openembedded-core/tree/meta/recipes-core/coreutils/coreutils_8.23.bb?h=master
[5] https://github.com/bmwcarit/meta-ros/issues/60
[6] https://github.com/bmwcarit/meta-ros/commit/db0c8d5cd1700174888071a6f617d307a2e050e0
[7] https://github.com/aballier
[8] https://github.com/ros/ros/pull/76
[9] https://github.com/aballier/ros/commit/bbf1f945c7e3a54efca912d38fe8b1b2f5b63988

Signed-off-by: Lukas Bulwahn <lukas.bulwahn@oss.bmw-carit.de>
Signed-off-by: Andreas Baak <andreas.baak@bmw-carit.de>
---
 recipes-ros/ros-comm/roslaunch_1.10.12.bb     |  1 -
 ...sk-1024-on-Linux-for-getting-disk-us.patch | 35 +++++++++++++++++++
 recipes-ros/ros/rosclean_1.10.11.bb           |  2 ++
 3 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 recipes-ros/ros/rosclean/0001-rosclean-Use-du-sk-1024-on-Linux-for-getting-disk-us.patch

diff --git a/recipes-ros/ros-comm/roslaunch_1.10.12.bb b/recipes-ros/ros-comm/roslaunch_1.10.12.bb
index 8865cce..7e59035 100644
--- a/recipes-ros/ros-comm/roslaunch_1.10.12.bb
+++ b/recipes-ros/ros-comm/roslaunch_1.10.12.bb
@@ -16,7 +16,6 @@ SRC_URI += "file://0001-increase-rosmaster-timeout.patch \
 ROS_PKG_SUBDIR = "tools"
 
 RDEPENDS_${PN} = "\
-    coreutils \
     python-textutils \
     python-logging \
     python-threading \
diff --git a/recipes-ros/ros/rosclean/0001-rosclean-Use-du-sk-1024-on-Linux-for-getting-disk-us.patch b/recipes-ros/ros/rosclean/0001-rosclean-Use-du-sk-1024-on-Linux-for-getting-disk-us.patch
new file mode 100644
index 0000000..8948b0e
--- /dev/null
+++ b/recipes-ros/ros/rosclean/0001-rosclean-Use-du-sk-1024-on-Linux-for-getting-disk-us.patch
@@ -0,0 +1,35 @@
+From 300ac79a86f580040a1676004e1e8758cc7c6781 Mon Sep 17 00:00:00 2001
+From: Alexis Ballier <aballier@gentoo.org>
+Date: Thu, 22 Jan 2015 09:56:41 +0100
+Subject: [PATCH] rosclean: Use "du -sk * 1024" on Linux for getting disk usage
+ since "du -b" is not supported by busybox du, while "du -k" is supported by
+ both coreutils and busybox.
+
+Upstream-Status: Submitted [https://github.com/ros/ros/pull/76]
+---
+ tools/rosclean/src/rosclean/__init__.py | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/tools/rosclean/src/rosclean/__init__.py b/tools/rosclean/src/rosclean/__init__.py
+index 5dafb05..6f051f1 100644
+--- a/tools/rosclean/src/rosclean/__init__.py
++++ b/tools/rosclean/src/rosclean/__init__.py
+@@ -121,13 +121,13 @@ def get_disk_usage(d):
+     """
+     Get disk usage in bytes for directory
+     :param d: directory path, ``str``
+-    :returns: disk usage in bytes (du -b) or (du -A) * 1024, ``int``
++    :returns: disk usage in bytes (du -k) * 1024 or (du -A) * 1024, ``int``
+     :raises: :exc:`CleanupException` If get_disk_usage() cannot be used on this platform
+     """
+     # only implemented on Linux and FreeBSD for now. Should work on OS X but need to verify first (du is not identical)
+     if platform.system() == 'Linux':
+         try:
+-            return int(subprocess.Popen(['du', '-sb', d], stdout=subprocess.PIPE).communicate()[0].split()[0])
++            return int(subprocess.Popen(['du', '-sk', d], stdout=subprocess.PIPE).communicate()[0].split()[0]) * 1024
+         except:
+             raise CleanupException("rosclean is not supported on this platform")
+     elif platform.system() == 'FreeBSD':
+-- 
+1.9.3
+
diff --git a/recipes-ros/ros/rosclean_1.10.11.bb b/recipes-ros/ros/rosclean_1.10.11.bb
index e838955..3184c17 100644
--- a/recipes-ros/ros/rosclean_1.10.11.bb
+++ b/recipes-ros/ros/rosclean_1.10.11.bb
@@ -6,3 +6,5 @@ LIC_FILES_CHKSUM = "file://package.xml;beginline=8;endline=8;md5=d566ef916e9dedc
 require ros.inc
 
 ROS_PKG_SUBDIR = "tools"
+
+SRC_URI += "file://0001-rosclean-Use-du-sk-1024-on-Linux-for-getting-disk-us.patch;striplevel=3"
-- 
GitLab