Could we test during upload if files on remote server changed since last upload?

Asked by Kamil Szot

While developing a website there are often occasions when direct modification of file on web server is needed. The problem is that there is no easy way of integrating this changes back into repository.

I made simple bash script for this purpose:
#!/bin/bash

ftp="ftp://user:<email address hidden>/path/to/site/"

# creating new branch for importing changes from remote copy
bzr ignore .remote
bzr commit -m "Added directory named .remote to ignores";
bzr branch --hardlink . .remote
# downloading remote changes

cd .remote
lftp $ftp -e 'mirror -n -v -x \.bzr-upload.revid -x \.bzrignore; quit'

# commiting them to created branch
bzr commit -m "files changed directly on ftp server"
cd ..
# merging branches
bzr merge .remote
# resolving conflicts
if [ -n "`bzr conflicts | grep -v 'Text conflict in '`" ]
then
    echo "There are some non-text conflicts, please resolve them manualy. After resolving please run this script once again.";
    exit;
fi

# resolve text conflicts using kdiff3 tool
for file in `bzr conflicts | awk 'BEGIN { ORS="\0"; } /^Text conflict in / { print $4; }'`;
do
 kdiff3 $file.BASE $file.THIS $file.OTHER -o $file
 [ -f $file.orig ] && rm $file.* && bzr resolve $file
done;

if [ -z "`bzr conflicts`" ]
then
 # commiting result of a merge to working branch
 bzr commit -m "remote changes merged with local changes"
 # uploading result of a merge to remote server
 bzr upload $ftp
        # ensure that .remote branch is up to date
 cd .remote
 rsync ../* ./ --exclude '.bzr' --exclude '.bzrignore' --exclude '.remote'
 bzr commit -m "remote changes merged with localchanges"
       # touch files hoping lftp mirror will download less files next time
 find -print0 | xargs -0 touch
 cd ..
fi;

It's far from optimal solution. It's way too noisy, and unnecessarily downloads some files from ftp.

Perhaps you could extend upload plugin with such functionality?
Or create another plugin supporting such workflow?

Question information

Language:
English Edit question
Status:
Answered
For:
bzr Upload plugin Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Vincent Ladeuil (vila) said :
#1

bzr-upload plugin is designed with the following workflow in mind:
- the remote files can't be handled by bzr (including tracking their modifications)
- the site is handled on a local site with bzr

From the above it becomes possible to upload only the modified files.

What you are trying to achieve is managing your remote files with bzr.
I'm afraid it will never be supported by bzr.

What the bzr-upload plugin is offering is copying your local files (where changes are tracked by bzr) to the remote site *assuming* you will never (like really never) modify the remote files. Changes on the remote files aren't (and really can't) be tracked, consider them read-only on the remote site (or write-only as far as the plugin is concerned).

What I would recommend in your case is downloading the files modified on the remote site each time you do a modification. Of course, before doing that, you must ensure that you have no uncommited local changes.

To make a long story short: if you want to track changes in a tree, you need bzr locally installed.

Revision history for this message
Vincent Ladeuil (vila) said :
#2

May be my previous answer is not appropriate for the question itself which is: 'Could we test during upload if files on remote server changed since last upload?'

The answer to that is: No.

bzr-upload assumes he knows what is on the remote site by considering that the remote files content is identified via the last revid uploaded.

Doing that allows to avoid downloading the remote files for comparison with the local files.

As you realize with your approach downloading the remote files can consume a lot of bandwidth. The main purpose of the plugin is exactly to *avoid* that.

Can you help with this problem?

Provide an answer of your own, or ask Kamil Szot for more information if necessary.

To post a message you must log in.