gfse: grammars in the cloud, work in progress

Cloud merging: when sharing grammars between two devices that previously each
had separate grammar directoies on the server, clean up one of the directories
and make it a symbolic link to the other.
This commit is contained in:
hallgren
2011-07-07 13:30:56 +00:00
parent f224ead86b
commit c7fffd861b
2 changed files with 32 additions and 1 deletions

View File

@@ -969,7 +969,12 @@ function download_from_cloud() {
var newdir="/tmp/"+location.hash.substr(1)
local.put("dir",newdir);
if(olddir && uploaded && newdir!=olddir) {
upload_json(function(){download_json(newdir)})
function download() { download_json(newdir) }
function rmolddir(){
ajax_http_get("upload.cgi?rmdir="+olddir+"&newdir="+newdir,
download,download)
}
upload_json(rmolddir)
}
else download_json(newdir)
}

View File

@@ -153,6 +153,32 @@ case "$REQUEST_METHOD" in
*) error400
esac
;;
rmdir=*)
dir=$(qparse "$QUERY_STRING" rmdir)
case "$dir" in
/tmp/gfse.*) # shouldn't allow .. in path !!!
path="$documentRoot$dir"
if [ -d "$path" ] ; then
ContentType="text/plain; charset=$charset"
cgiheaders
cd "$path"
rm *.gf *.gfo *-*.json *.pgf grammars.cgi
cd ..
rmdir "$path"
newdir=$(qparse "$QUERY_STRING" newdir)
case "$newdir" in
/tmp/gfse.*) # shouldn't allow .. in path !!!
newnode="${newdir##*/}"
oldnode="${path##*/}"
ln -s "$newnode" "$oldnode"
esac
else
error404
fi
;;
*) error400
esac
;;
download=*)
file=$(qparse "$QUERY_STRING" download)
case "$file" in