-   Linux - Newbie (
-   -   Can't find file to patch (

iFunction 03-30-2016 06:00 AM

Can't find file to patch
editted as when read back, I seem to have deleted most of the information

I know there is a ton of information about this particular question, but I don't understand it.

I have a patch file, that I have made, that is to be used on a freshly installed Raspbian image and applied from an separate file that will be dragged onto the desktop.

when I run the install script:

sudo patch -p0 ./patch_files/screen.patch
It says can't find file to patch, and I have to input it manually.

I can't figure this out, I was assuming that the first line was where the patch file is to be found, and that the second line is the destination of the file to be patched, but when I try to install it, it just says can't find file, yet there it is on the second line. Why doesn't it find it, this doesn't make any sense????

grail 03-30-2016 07:18 AM

Try the man page and pay specific attention to the -p option as this indicates where you are in relation to the file being patched, ie. -p0 means you are the same distance from the file being patched as the patch file is (is this correct?)

syg00 03-30-2016 07:40 AM

And you need to "feed" the patchfile in - either using redirection or the "-i" option.

iFunction 03-30-2016 08:58 AM

OK, I have just tried p0 right up to p10 and it asks me for the file every time. This doesn't make sense to me... can this be used for this type of thing, or is it really used for updating code to be compiled like C++ where the source files are likely to be in the same place. If there the command really needs a from location that is relational to the file that is being updated, I take it it's not that useful for modifying files in bash?

grail 03-30-2016 09:54 AM

It is for updating any text based file, as patch knows nothing of programming languages. What happens if you run the patch from within the directory where the file to be changed is with no -p option and only the -i option?

Is it also possible for you to show us the patch file?
I also presume this was created with diff?

iFunction 03-30-2016 10:12 AM

I have copied the file to the same directory as the file to be patched, and I can apply the patch manually if I am also in that directory, so how can I do that from a script?

grail 03-30-2016 11:52 AM

Simplest way would be to cd to the directory prior to applying the patch.

iFunction 03-30-2016 12:44 PM

I've done that too, and it still doesn't work, I'm at a loss here, this is not the entire script:

sudo cp ./config.patch /boot/
cd /boot/
patch < config.patch

I now have absolutely no idea what I am doing wrong, but if I do that manually it works, if I try to run this in a script, the script seems to run, but on inspecting /boot, the config.patch file is there, but it hasn't done the patch.

I have no idea where to look now, I have spent all day trying to solve this.

grail 03-30-2016 01:07 PM

Do you not have to use sudo on the call to patch as well? Or is it a typo?

iFunction 03-30-2016 02:54 PM

Ah, sorry , typo.

grail 03-30-2016 11:36 PM

Can you put up the output of running the script? I agree that on paper it appears it should work. Are you sure nothing else in your script is causing this to somehow fail?

iFunction 03-31-2016 03:55 AM

Ok, I discovered some things last night. I am suspecting it not to be the script, as it is now simply three lines all commands use sudo, and when run, I get a message stating cd command not found, so removing that, the script still works under the following circumstances:

So if I create the patch using diff in the folder of the file to be patched, then I can move the patch file created anywhere after that and it will work. Is it supposed to be that diff can only be used from one location? ideally, I would like to be able to make it from my own development and learning area of the file system, as in the script I can always move the patch to the folder run it and delete it once the patch has happened, I would rather do the building away from system files i.e. not have to cd to the particular folder to get patch to work, as I have already noticed how easy it is to break an OS with a slip of a finger. Currently this is the only way I can get diff and patch to work:
make updated file,
send it to folder with original in
cd to folder
create patch with diff
move updated file and patch file back to original location,

I was hoping to do it this way:
create new file in current location
create patch using diff

then to run copy patch to folder with original
verify patch has worked
delete patch file

it appears though that making the patch file in a different folder is causing the problem even though the full file path is in the file. Another thing I noticed is that changing the patch name to something meaningful will prevent it working also.

The curious thing about all this is that no matter what I do I can always use the patch file manually if I cd to the folder as well, no matter where the patch was made or what I have decided to call the patch file.

I am clearly not understanding something though and I am also certain that it is a simple rule that is being overlooked as I have not found any of these restrictions in any documentation.

Some insight would be appreciated, or a website that gives a full explanation as to how patch and diff work and are used, I have only found how to do specifics so far, and none of these specific type tutorials are relevant as they are referring to source code which will traditionally be all in the same place. So far I am still not in a position where I can guarantee a patch will work on the specific system in the same way I can guarantee "sed" will work on our system. Patch and diff seems potentially a much better alternative to sed though I am not finding it as well documented as sed currently.

iFunction 03-31-2016 09:05 AM

Ok this is getting impossible, I have been following this tutorial to the letter:

so now I can patch a file on the condition that nothing moves in or out of that folder. As soon as I move to a different folder, I just get:

patch: **** Only garbage was found in the patch input
When I say move to a different folder, I mean that I am working from the desktop and on the desktop I have created a folder called "test". I copy the original file and the patch file to "test" cd to "test" and then patch with the line:

patch original -i patch -o updated
yet I can use this line on the files on the desktop. Copy them to another folder and again only garbage.

What is going on here? Why is diff and patch so amazing when it is so hard to learn to use in it's most basic of forms?

For clarity, all this is done on a Raspberry Pi, and in response to:

echo $0
I get

so I don't know if the shell is causing the problems but I can't see why this is so difficult, I really don't think of myself as stupid, but maybe I simply am

grail 03-31-2016 11:29 AM

Not knowing too much about Raspberry Pi's, what versions are you running of patch and diff?

What is the diff command you are running to create the patch file?

Calling your patch file 'patch' would make it difficult to recognise quickly between the command and the file name (but you may have done this for simplicity, so just a thought :) )

I noticed you said previously that the cd command failed, I find this particularly odd as it is a very general command to be missing??

I generally find that if I patch the file in the place where the original will be on the end machine I get little difficulty. So testing in another location does make sense but I would think you then need to be able to cd to where you need to go otherwise patch will be looking ion the wrong location.

Hopefully someone else might chime in and point you to a good reference. Most of my patching experience came from performing the steps provided on LFS. I simply
looked inside the patch files and used the same diff as they had and have had little to issues :)

iFunction 03-31-2016 11:39 AM

Well I've discovered some of the problems, here is an update of what I have found in case I'm not the only person that finds this one a battle. The file I have been practicing on is /boot/config.txt (it's a dodgy one to play with I know) and bash won't allow root privileges in a script (well there are ways around it, but I can more than see why this is in place: security). All this time the patch I did should have worked and indeed did if it was manually applied.

Now to explain as best I can the thread title problem. So, the whole "can't find file to patch", basically, the command "patch" works where it currently is, so in terminal, you have to change directory to the same file as the one you want to patch. As a result the same works in a script, you have to cd to the location, then it will work happily.

As for the "-p0" I have not been able to figure that out at all, my assumption is that it is to do with the relationship of the location between the file being patched and the patch file itself, though I haven't managed to test any of that because as soon as I put in -p0 the patch command just throws can't find errors again. Any explanation as to how this actually works would help immensely.

As for my original problem, it simply can't be done as all the patching is for system configuration files for things like keyboard shortcuts, screen resolution, and network interface configuration, and all of those require root privileges and as noted earlier, bash scripts do not support root privileges since bash 2.71 I understand.

Kind regards

All times are GMT -5. The time now is 08:35 AM.