Project

General

Profile

Bug #1004

In scripts: use portable test for absolute paths

Added by John Abbott over 7 years ago. Updated about 7 years ago.

Status:
Closed
Priority:
High
Assignee:
Category:
Portability
Start date:
01 Feb 2017
Due date:
% Done:

100%

Estimated time:
2.01 h
Spent time:

Description

Anna has just reported that some scripts give incorrect errors about paths not being absolute.

The problem probably derives from the fact that on some Microsoft systems paths beginning with a double slash are handled specially (i.e. /foo and //foo are not the same)

History

#1 Updated by John Abbott over 7 years ago

  • Status changed from New to In Progress
  • Assignee set to John Abbott
  • Priority changed from Normal to High
  • % Done changed from 0 to 10

I have found a plausible solution on StackExchange (256434):
the following (Bourne) shell function was given as a solution

is_absolute() {
  case "$1" in
    ///* | //) true;;
          //*) false;; # on some systems, //foo is special and is
                       # not an absolute path. // alone is /
           /*) true;;
            *) false
  esac
}

I am not sure what is the best way to use this fn in scripts: here are two possibilities:

is_absolute "$file_name" 
if [ $? -ne 0 ]
then
  echo "Not absolute" 
  exit 1
fi

The next is more compact but possibly less natural to read (and spawns a subshell?)

is_absolute "$file_name" ||
(
  echo "not absolute" 
  exit 1
)

#2 Updated by John Abbott over 7 years ago

  • % Done changed from 10 to 50

Anna reports that the modified script worked as desired on M$ plaform.
So I have changed the other scripts (which need to test for abs paths) in the same way -- in the end I used the "possibly less readable version" (as it is less ugly to my eye).

I'll check in when next I have access to VPN+CVS.

#3 Updated by John Abbott over 7 years ago

  • Subject changed from In scripts: use portabel test for absolute paths to In scripts: use portable test for absolute paths
  • Status changed from In Progress to Feedback
  • % Done changed from 50 to 90

No problems has been reported so far, so moving to "feedback".

I think the solution I have chosen should be compatible with the old "Bourne" shell. (but I actually use bash).

#4 Updated by John Abbott over 7 years ago

  • Target version changed from CoCoALib-0.99560 to CoCoALib-0.99550 spring 2017

#5 Updated by John Abbott about 7 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 90 to 100

Closing after 2 months in feedback without any problems being reported.

#6 Updated by Anna Maria Bigatti about 7 years ago

  • Estimated time set to 2.01 h

Also available in: Atom PDF