DFWEBOS_DATA_DIR="${DFWEBOS_ROOT}/data"
DFWEBOS_DATA_STORAGE_DIR="${DFWEBOS_DATA_DIR}/storage"
DESIRED_OWNER="1000:1000"

if [[ ! -d "${DFWEBOS_DATA_STORAGE_DIR}" ]]; then
	mkdir -p "${DFWEBOS_DATA_STORAGE_DIR}"
fi

filebrowser_correct_permission() {
	local -r path="${1}"

	if [[ -d "${path}" ]]; then
		owner=$(stat -c "%u:%g" "${path}")

		if [[ "${owner}" != "${DESIRED_OWNER}" ]]; then
			chown "${DESIRED_OWNER}" "${path}"
		fi
	fi
}

filebrowser_correct_permission "${DFWEBOS_DATA_DIR}"
filebrowser_correct_permission "${DFWEBOS_DATA_STORAGE_DIR}"