View Issue Details

IDProjectCategoryView StatusLast Update
0002306OpenFOAMPatchpublic2016-10-25 17:14
ReporterwyldckatAssigned Tohenry 
PrioritynormalSeverityminorReproducibilitysometimes
Status resolvedResolutionfixed 
Product Version 
Fixed in Version 
Summary0002306: foamCleanPath: Problems with usernames and paths that have the @ symbol
DescriptionIn the past 2 weeks there have been two bug reports on the OpenFOAM+ bug tracker, first one referring to OpenFOAM+ v1606+ and another one a few hours ago about OpenFOAM v4 Deb pack installation on Ubuntu 16.04.1, with this specific problem.

The problem occurs with HPC environments that rely on domain names that use email addresses or some other naming convention that relies on the at symbol "@" to reference the user-name's location, e.g. "ofuser@guests". The error message is considerably long, but starts with the following 4 lines:

  sed: -e expression #1, char 72: unknown option to `s'
  sed: -e expression #1, char 111: unknown option to `s'
  sed: -e expression #1, char 111: unknown option to `s'
  /opt/openfoam4/bin/foamCleanPath: 110: /opt/openfoam4/bin/foamCleanPath: sed: not found


This affects all OpenFOAM versions/forks so far and the attached file "foamCleanPath" for updating "bin/foamCleanPath" on OpenFOAM 4.x and dev has a possible fix for this, namely by replacing the "@" symbols for "|" in the following line:

  - dirList=$(echo "$dirList:" | sed -e "s@${wildcard}[^:]*:@@g")
  + dirList=$(echo "$dirList:" | sed -e "s|${wildcard}[^:]*:||g")



The choice for the pipe character "|" was because this symbol should not be used for file/folder names (although it can be used on Linux/POSIX systems), since it could conflict with the piping commands on the shell, such as the one already in use above.
TagsNo tags attached.

Activities

wyldckat

2016-10-25 00:14

updater  

foamCleanPath (3,990 bytes)
#!/bin/sh
#------------------------------------------------------------------------------
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
#   \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
#    \\/     M anipulation  |
#-------------------------------------------------------------------------------
# License
#     This file is part of OpenFOAM.
#
#     OpenFOAM is free software: you can redistribute it and/or modify it
#     under the terms of the GNU General Public License as published by
#     the Free Software Foundation, either version 3 of the License, or
#     (at your option) any later version.
#
#     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
#     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
#     for more details.
#
#     You should have received a copy of the GNU General Public License
#     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
#
# Script
#     foamCleanPath
#
# Description
#     Usage: foamCleanPath [-strip] path [wildcard] .. [wildcard]
#
#     Prints its argument (which should be a ':' separated path)
#     without all
#         - duplicate elements
#         - elements whose start matches a wildcard
#         - inaccessible directories (with the -strip (at your option)
#
# Note
#     - this routine will fail when directories have embedded spaces
#     - false matches possible if a wildcard contains '.' (sed regex)
#     - the wildcards can themselves can be written together and separated
#       by colons or whitespace
#------------------------------------------------------------------------------
usage() {
    cat <<USAGE 1>&2
Usage: ${0##*/} [OPTION] path [wildcard1] .. [wildcardN]
options:
  -strip            remove inaccessible directories
  -help             print the usage

  Prints its argument (which should be a ':' separated list) cleansed from
    - duplicate elements
    - elements whose start matches one of the wildcard(s)
    - inaccessible directories (with the -strip option)

  Exit status
      0  on success
      1  for miscellaneous errors.
      2  initial value of 'path' is empty

USAGE
    exit 1
}


unset strip
# parse options
while [ "$#" -gt 0 ]
do
    case "$1" in
    -h | -help)
        usage
        ;;
    -strip)
        strip=true
        shift
        ;;
    *)
        break
        ;;
    esac
done


[ "$#" -ge 1 ] || usage

dirList="$1"
shift

[ -n "$dirList" ] || exit 2    # quick exit on empty 'dirList'


##DEBUG echo "input>$dirList<" 1>&2

# preserve current IFS and split on colon or whitespace
oldIFS="$IFS"
IFS=': '

# "wildcard1 ... wildcardN" may have been passed as a single parameter
# or may contain ':' separators
set -- $*

# strip out wildcards via sed
while [ "$#" -ge 1 ]
do
    wildcard=$1
    shift
    ##DEBUG echo "remove>$wildcard<" 1>&2
    if [ -n "$wildcard" ]
    then
        dirList=$(echo "$dirList:" | sed -e "s|${wildcard}[^:]*:||g")
    fi
done

# split on ':' (and on space as well to avoid any surprises)
IFS=': '
set -- $dirList

##DEBUG echo "intermediate>$dirList<" 1>&2

# rebuild the list from scratch
unset dirList
for dir
do
    ##DEBUG echo "check>$dir<" 1>&2
    #- dirs must exist
    if [ -e "$dir" ]
    then
        #- no duplicate dirs
        duplicate=$(echo " $dirList " | sed -ne "s: $dir :DUP:p")

        if [ ! "$duplicate" ]
        then
            dirList="$dirList $dir"
        fi
    elif [ "$strip" != true ]
    then
        # Print non-existing directories if not in 'strip' mode.
        dirList="$dirList $dir"
    fi
done

# split on whitespace
IFS=' '
set -- $dirList

# rejoin on ':'
IFS=':'
dirList="$*"

# restore IFS
IFS="$oldIFS"

##DEBUG echo "output>$dirList<" 1>&2
echo "$dirList"

#------------------------------------------------------------------------------
foamCleanPath (3,990 bytes)

henry

2016-10-25 17:14

manager   ~0007066

Resolved in OpenFOAM-dev by commit 1685585b829d853b983517321911b5a3f819de29

Resolved in OpenFOAM-4.x by commit a6a964b26579822b082661a2ab0d40a7fd6926f4

Issue History

Date Modified Username Field Change
2016-10-25 00:14 wyldckat New Issue
2016-10-25 00:14 wyldckat Status new => assigned
2016-10-25 00:14 wyldckat Assigned To => henry
2016-10-25 00:14 wyldckat File Added: foamCleanPath
2016-10-25 17:14 henry Status assigned => resolved
2016-10-25 17:14 henry Resolution open => fixed
2016-10-25 17:14 henry Fixed in Version => 4.x
2016-10-25 17:14 henry Note Added: 0007066