Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #16 Use JCR context for checkout #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kitarek
Copy link

@kitarek kitarek commented May 11, 2018

For the other commands filesystem context is retained.
As I proposed in issue #16 I was able to prepare and test a PR.

For the other commands filesystem context is retained.
Copy link
Contributor

@alexkli alexkli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch! A few comments inline.

function jcr_to_filesystem() {
local jcrPath=$1
# Handle namespaces and a default empty one
echo ${jcrPath} | sed -e 's#\/\([^:]*\):#/_\1_#g' | sed -e 's#/:#/#g'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. sed

AFAICS, it seems it could match /path/jcr for input /path/jcr:content which we wouldn't want.

It probably should include the slash in the not-match array [^:\/] so that it does not go beyond a / when it searches for the next :.

  1. sed

How did you come across /:? Isn't that an input error that we should probably throw on? Or is it a special case cleanup of the 1. sed and if yes, shouldn't that be fixed in the first one?

While we are at it, we need to double-escape a leading _ IIUC. This is the logic we have to copy here – jcr (repo) to filesystem (platform): https://github.com/apache/jackrabbit-filevault/blob/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/PlatformNameFormat.java#L66-L114
Note the StringBuffer initialized with a leading _.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, we could apply the regexp approach to filesystem_to_jcr() as well instead of the hardcoded list. The underscore escaping can only happen for the first char after a slash, and if it's /path/__something then it shall become /path/_something IIUC:

https://github.com/apache/jackrabbit-filevault/blob/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/util/PlatformNameFormat.java#L137-L174

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexkli: Thanks for thorough review! It makes sense to reiterate on this and fix/simplify the code. At least it was working for me. Let me find some time this week to fix this and I hope we can finish it soon.

My replies (but not code yet fixed):

  1. Right, regexp usually takes the longest string that is able to match so we need to include both boundaries: / & : instead of just :
  2. /: is a special allowed case of a default namespace (I briefly reviewed JCR standard looking for so called XML namespace prefix). The problem I see here is that we will end up with: __propertyName which is not exactly the same as propertyName. We probably should review how Vault deals with such things under the hood. I'm okay to drop this if Vault manages double _.
  3. Probably because of _ escape __ will be treated as _ in that case so we cannot drop 2.

else
humanFilter=$filter
humanFilter=$jcrFilter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it now makes more sense to always print the filesystem path upon put and the jcr path upon get (see messages below). AFAICS, the path exists in the checkout case, so it would print the filesystem path here, whereas in later gets it would print the jcr path, a bit confusing. wdyt?

# get dirname and basename for each
pathDirname=${path%/*}
filterDirname=${filter%/*}
filterDirname=${fsFilter%/*}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to rename this to fsFilterDirname for consistent naming.

pathBasename=${path##*/}
filterBasename=${filter##*/}
filterBasename=${fsFilter##*/}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to rename this to fsFilterBasename for consistent naming.

@@ -577,15 +582,18 @@ else
# get jcr path after jcr_root
filter=${path##*/jcr_root}

# Deducting JCR path
fsFilter="${filter}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$filter isn't used anymore later, so I suggest to merge the lines above and just have

fsFilter=${path##*/jcr_root}

and below use

jcrFilter=$(filesystem_to_jcr "${fsFilter}")

which should make it more obvious what's converted.

@@ -535,7 +540,8 @@ done
if [ $action == "checkout" ]; then
# special checkout init steps
# path argument must be a jcr path
filter="$path"
jcrFilter="$path"
fsFilter=$(jcr_to_filesystem "$path")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest to do fsFilter=$(jcr_to_filesystem "$jcrFilter") so it's a little more obvious.

@kitarek
Copy link
Author

kitarek commented May 17, 2018

BTW: apart from the above comments, I haven't check yet the script with shellcheck tool.

WDYT to review it via that tool or it was already done in the past for repo, @alexkli ?

I would feel personally safer applying this PR after reviewing additionally shellcheck report on top of all your suggestions.

@alexkli
Copy link
Contributor

alexkli commented May 17, 2018

Haven't run shellcheck or the like, curious to see what it will say 😄

@kitarek
Copy link
Author

kitarek commented May 17, 2018

@alexkli I'm committing to fix most of them :-D

This is the output from: shellcheck -s bash repo/repo

In repo/repo line 46:
readonly PROGNAME=$(basename $0)
                             ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 131:
if [ $action == "checkout" ]; then
     ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 137:
if [ $action == "checkout" ]; then
     ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 144:
elif [ $action == "put" ]; then
       ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 146:
elif [ $action == "get" ]; then
       ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 148:
elif [ $action == "status" ]; then
       ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 150:
elif [ $action == "diff" ]; then
       ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 155:
elif [ $action == "localdiff" ]; then
       ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 160:
elif [ $action == "serverdiff" ]; then
       ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 167:
if [ $action == "checkout" ]; then
     ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 226:
    exit $1
         ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 233:
    cleanup ${2:-1}
            ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 256:
        echo "$(cd "$1"; pwd)"
                ^-- SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.


In repo/repo line 260:
            echo "$(cd "${1%/*}"; pwd)/${1##*/}"
                    ^-- SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.


In repo/repo line 291:
    echo ${jcrPath} | sed -e 's#\/\([^:]*\):#/_\1_#g' | sed -e 's#/:#/#g'
         ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 313:
    filter=$(urldecode $filter)
                       ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 315:
    echo $filter
         ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 326:
    echo $name
         ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 342:
    <filter root="$(to_xml $filter)"/>
                           ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 350:
<entry key="name">$(to_xml $pkgName)</entry>
                           ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 351:
<entry key="version">$(to_xml $pkgVersion)</entry>
                              ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 352:
<entry key="group">$(to_xml $pkgGroup)</entry>
                            ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 374:
    for ignoreFile in `find "$path" -name .vltignore`; do
                      ^-- SC2044: For loops over find output are fragile. Use find -exec or a while read loop.
                      ^-- SC2006: Use $(..) instead of legacy `..`.


In repo/repo line 379:
        cat $ignoreFile | sed -e "s,^,$relPath," >> "$1"
            ^-- SC2086: Double quote to prevent globbing and word splitting.
            ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


In repo/repo line 385:
    pushd "$1" > /dev/null    
    ^-- SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.


In repo/repo line 387:
    popd > /dev/null
    ^-- SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.


In repo/repo line 395:
    curl -u $credentials -f -s -S $1
                                  ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 423:
    if [ $? -ne 0 ]; then
         ^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.


In repo/repo line 500:
if [ $action == "st" ]; then action="status"; fi
     ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 604:
    source "$repoCfg"
    ^-- SC1090: Can't follow non-constant source. Use a directive to specify location.


In repo/repo line 641:
pathBasename=${path##*/}
^-- SC2034: pathBasename appears unused. Verify it or export it.


In repo/repo line 642:
filterBasename=${fsFilter##*/}
^-- SC2034: filterBasename appears unused. Verify it or export it.


In repo/repo line 645:
    humanFilter=$fsFilter/*
                ^-- SC2125: Brace expansions and globs are literal in assignments. Quote it or use an array.


In repo/repo line 663:
tmpDir=`mktemp -d -t repo.XXX`
       ^-- SC2006: Use $(..) instead of legacy `..`.


In repo/repo line 667:
write_excludes $excludes
               ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 678:
    rsync -avq --exclude-from=$excludes "$path" "$tmpDir/jcr_root$filterDirname"
                              ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 681:
    rm -f $excludes
          ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 683:
    build_zip $tmpDir
              ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 686:
        unzip -l $zipfile | grep "   jcr_root$fsFilter"
                 ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 694:
    upload_pkg $zipfile
               ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 695:
    install_pkg $pkg
                ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 696:
    delete_pkg $pkg
               ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 702:
    build_zip $tmpDir
              ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 705:
    upload_pkg $zipfile
               ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 706:
    build_pkg $pkg
              ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 709:
    rm -rf $tmpDir/*
           ^-- SC2115: Use "${var:?}" to ensure this never expands to /* .
           ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 712:
    download_pkg $pkg $zipfile
                 ^-- SC2086: Double quote to prevent globbing and word splitting.
                      ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 713:
    delete_pkg $pkg
               ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 715:
    pushd $tmpDir > /dev/null
    ^-- SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
          ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 717:
    popd > /dev/null
    ^-- SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.


In repo/repo line 726:
        rsync -avq --exclude-from=$excludes "$path" "$diffbase/LOCAL$filterDirname"
                                  ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 729:
        ln -s $tmpDir/jcr_root $diffbase/REMOTE
              ^-- SC2086: Double quote to prevent globbing and word splitting.
                               ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 732:
        pushd $diffbase > /dev/null
        ^-- SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
              ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 749:
        popd > /dev/null
        ^-- SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.


In repo/repo line 754:
            unzip -l $zipfile | grep "   jcr_root$fsFilter"
                     ^-- SC2086: Double quote to prevent globbing and word splitting.


In repo/repo line 762:
        rsync -avq --delete --exclude-from=$excludes "$tmpDir/jcr_root/$fsFilter" "$pathDirname"
                                           ^-- SC2086: Double quote to prevent globbing and word splitting.


@alexkli
Copy link
Contributor

alexkli commented May 17, 2018

Ok, but I would suggest to do the shellcheck work in a separate PR, since it will affect the whole script, and shouldn't be mixed with the changes for this issue.

@alexkli alexkli added bug waiting for response Waiting for a response from the reporter(s) labels Jul 22, 2019
@alexkli alexkli added this to In Progress in repo tool Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug waiting for response Waiting for a response from the reporter(s)
Projects
repo tool
  
In Progress
Development

Successfully merging this pull request may close these issues.

None yet

2 participants