Bug? I seem to be getting the wrong exit code

Hi all. Perhaps I'm over tired, but the command in the following snippet, which tries to fetch a non-existent file - from a non-existent directory, but on an existing remote - gives an error-code of zero. Should not the code be 3 or 4?

$ rclone copy enc-b2:/X230/tarball/ball.tar /tmp/syncIn_40T && echo OK
0 / 0 Bytes, -, 0 Bytes/s, ETA -
OK
$ echo "$?"
0

OS: Linux
Bash: GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
Rclone: v1.51.0

One quibble, if I may: the shell variable $? picks up the result code of the last command executed. In the case of the command above, the last command executed was the echo command (which worked). Now, however, the && means the echo is only run if the prior command (rclone copy ...) was "successful"; apparently, rclone returned an exit status of 0 (zero) to allow the echo. It should likely not be doing so; the man page says it should be producing a non-zero exit status and the echo command should not be getting executed.

Ah yes - my echo "$?" does not make sense. But as you say there does seem to be something wrong here.

Indeed I've queried the exit code without an intervening command and it is 0 - which, so far as I can tell, it should not be. (And having it be zero does cause problems: the advertised exit-codes are there to provide information about what is going on.)

Can you please run the command again with debug logs?

The problem is the semantics of the copy command mixed with the semantics of bucket based remotes....

Rclone doesn't know whether enc-b2:/X230/tarball/ball.tar is a file or a directory. If neither exist then it assumes it is a directory.

When rclone comes to list the non-existent directory on a bucket based remote s3/b2/gcs/etc the directory listing is successful, just shows no files in it. This is because bucket based remotes don't actually have a concept of directories.

Making listing an empty directory on bucket based remotes produce a error would fix this problem, but it would break an awful lot of other things!

What you really want is rclone copyfile which doesn't exist... However it does in the rc so you could use this which will give an error if the source file doesn't exist

rclone rc --loopback operations/copyfile srcFs=b2:bucket srcRemote=non-existent-file dstFs=/tmp dstRemote=sdfsdf

See https://rclone.org/rc for more info!

Maybe I should add a --file flag to rclone copy or something like that, or add an rclone copyfile command

Thanks, ncw. That seems to work - it fetches the file if it exists and gives an error if it does not.

I would appreciate it if you made available a command that was more in the syntax of the normal - as against 'remote control' ('rc') - version of rclone. For, I have spent ages integrating my existing approach to the problem into a library that runs various rclone jobs of mine; and now that will not work, at least without considerable modification, because of the special syntax of rclone rc.

Also, the error-upon-non-existence seems a bit cryptic to me: 'loopback call failed: object not found' - well, OK, but was it the source or was it the destination that was not found?

Here is a minor bug report an an observation.

Minor bug report: when using variants of the command at issue, rclone told me '[. .] is a not a regular file' (sic, i.e.: 'is a not a').

Observation: setting the 'dstFs' variable - which does not seem designed for a local file system - to a value containing a subpath fails. I mean: giving it the value '/tmp' works, but '/tmp/someFolder' does not. (But, still, one can put 'someFolder' into the 'dstRemote' variable.)

Can you please make a new issue on github about this. Maybe you could help implement it?

Thanks, I've fixed that.

Any of these forms should work

$ rclone rc --loopback operations/list fs=/tmp remote=a
{
	"list": [
		{
			"IsDir": false,
			"MimeType": "text/plain; charset=utf-8",
			"ModTime": "2020-04-15T12:44:05.482319986+01:00",
			"Name": "file.txt",
			"Path": "a/file.txt",
			"Size": 4
		}
	]
}
$ rclone rc --loopback operations/list fs=/tmp/a remote=""
{
	"list": [
		{
			"IsDir": false,
			"MimeType": "text/plain; charset=utf-8",
			"ModTime": "2020-04-15T12:44:05.482319986+01:00",
			"Name": "file.txt",
			"Path": "file.txt",
			"Size": 4
		}
	]
}
$ rclone rc --loopback operations/list fs="/" remote="tmp/a"
{
	"list": [
		{
			"IsDir": false,
			"MimeType": "text/plain; charset=utf-8",
			"ModTime": "2020-04-15T12:44:05.482319986+01:00",
			"Name": "file.txt",
			"Path": "tmp/a/file.txt",
			"Size": 4
		}
	]
}

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.