trinapicot / unraid-diskmv

A set of utilities to move unRAID user share directories between disks
The Unlicense
32 stars 4 forks source link

Accept single files in root folder of user share #1

Closed jbrodriguez closed 9 years ago

jbrodriguez commented 9 years ago

trinapicot,

Some users of unBALANCE, reported they couldn't transfer files sitting at the root of the user share.

I made some changes to the diskmv script

I didn't make a proper PR, waiting for you to figure out if such a change is ok.

# if [ ! -d "/mnt/user/$MERGEDIR" ]
# then 
#   echo "'$1' is not a valid user share directory." >&2
#   usage >&2
#   exit 1
# fi
-echo "diskmv finished"
+printf "diskmv finished\n"

 if [ ! $doit == 'true' ]; then
-  echo "... but it ran in test mode"
-fi
-
-echo
+  printf "... but it ran in test mode\n"
+fi
trinapicot commented 9 years ago

I would not just comment out that section, it is there make sure the user input is valid (it needs to be a part of the user share system). Perhaps the test could be changed from -d to -e to allow diskmv to work on single files as well as directories, but I designed diskmv to act on directories only. I'll have to ponder the consequences of opening it up to move single files.

I don't understand why you made the printf change. In my bash terminal, echo adds a newline by default, so your printf calls look equivalent to what was already there. If there is a good reason, I'm not opposed to changing all of the echo calls to printf.

jbrodriguez commented 9 years ago

@trinapicot,

Regarding 2 (printf), I think it has more to do with how Go handles echo output (and in general any shell command).

What happens is this

I: 2015/05/19 11:21:31 core.go:314: diskmv finished
I: 2015/05/19 11:21:31 core.go:314: I: 2015/05/19 11:21:31 core.go:403: disk.Path = /mnt/disk8 | item.Path = Media/Tv/Show | dst = /mnt/disk2

The first line is ok The second line should finish before the second "I: 2015/...."

I tried some echo variations (adding "\n", calling it with echo $'line\n'), but none of them worked.

I used printf based on this stackoverflow thread, which may or may not be 100% correct :)

Regarding 1 (directory), you're absolutely right.

You need to make sure that user input is part of the user share. I didn't see that.

Let me know if "-e" works, from an "unintended side-effects" point of view (I'm not a bash/rsync expert).

I'll wait for your feedback, before uploading a new version.

trinapicot commented 9 years ago

Regarding 2 (printf), if the diff you quoted is complete, you have removed the final echo statement (which has the effect of a blank new line at the terminal). I'm wondering if that was the solution to your problem since you didn't have to change all of the other echo statements. Does Go just have a problem with a blank new line? What happens if you add a blank newline at the end with printf "\n"?

jbrodriguez commented 9 years ago

printf "\n" didn't work.

But printf " \n" (a space before the newline character) worked !

trinapicot commented 9 years ago

My conclusion is that your problem is caused by the solitary newline character output at the end of diskmv, not the difference between echo and printf. Do you agree?

I don't know anything about Go, but if you are using it to run a bash script, it seems like it should be able to handle a solitary newline character as output.

jbrodriguez commented 9 years ago

Certainly seems so.

trinapicot commented 9 years ago

@jbrodriguez Committed changes to allow single file as input to diskmv. Also removed solitary newline character in output.

jbrodriguez commented 9 years ago

Thanks @trinapicot, I really appreciate your input !