BUILD_RESULT=$?
-# Newly created files during above docker run can have different ownership.
-# This may cause some problems, for example, some jenkins slaves or developers
-# can't remove built files due to lack of permission.
-# To address this issue, let's change owner of all files
-# in NPU_Compiler to owner of NPU_Compiler.
-NNFW_OWNER_UID=$(stat -c "%u" $HOST_HOME)
-NNFW_OWNER_GID=$(stat -c "%g" $HOST_HOME)
-
-CMD="chown -R $NNFW_OWNER_UID:$NNFW_OWNER_GID $DOCKER_HOME"
-docker run $DOCKER_RUN_OPTS $DOCKER_ENV_VARS $DOCKER_VOLUMES $DOCKER_IMAGE_NAME $CMD
+source $SCRIPT_ROOT/docker_helper
+restore_ownership $HOST_HOME $DOCKER_HOME
exit $BUILD_RESULT
--- /dev/null
+# Newly created files during docker run can have different ownership.
+# This may cause some problems, for example, some jenkins slaves or developers
+# can't remove built files due to lack of permission.
+# To address this issue, let's change owner of all files and subdirector
+# to owner of host directory.
+#
+# Parameters:
+# $1 : host directory
+# $2 : docker directory
+#
+# Requires following variables defined
+# DOCKER_RUN_OPTS, DOCKER_ENV_VARS, DOCKER_VOLUMES, DOCKER_IMAGE_NAME
+function restore_ownership() {
+ if [ -z "$1" ]
+ then
+ echo "Requires host path"
+ exit 1
+ fi
+ _HOST_DIR=$1
+
+ if [ -z "$2" ]
+ then
+ echo "Requires docker path"
+ exit 1
+ fi
+
+ _DOCKER_DIR=$2
+
+ _OWNER_UID=$(stat -c "%u" $_HOST_DIR)
+ _OWNER_GID=$(stat -c "%g" $_HOST_DIR)
+ CMD="chown -R $_OWNER_UID:$_OWNER_GID $_DOCKER_DIR"
+ docker run $DOCKER_RUN_OPTS $DOCKER_ENV_VARS $DOCKER_VOLUMES $DOCKER_IMAGE_NAME $CMD
+}