-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
binary control files #220
base: master
Are you sure you want to change the base?
binary control files #220
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
package org.vafer.jdeb; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
|
@@ -103,13 +104,19 @@ void buildControl(BinaryPackageControlFile packageControlFile, File[] controlFil | |
if ("conffiles".equals(file.getName())) { | ||
foundConffiles = true; | ||
} | ||
|
||
if (CONFIGURATION_FILENAMES.contains(file.getName()) || MAINTAINER_SCRIPTS.contains(file.getName())) { | ||
FilteredFile configurationFile = new FilteredFile(new FileInputStream(file), resolver); | ||
configurationFile.setOpenToken(openReplaceToken); | ||
configurationFile.setCloseToken(closeReplaceToken); | ||
addControlEntry(file.getName(), configurationFile.toString(), outputStream); | ||
|
||
} else if (file.getName().endsWith(".bin")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Frankly speaking I am not such a fan of adding some new rule about the file name. Maybe we should just make this work with https://github.com/mlhartme/jdeb/blob/binanry_control/src/main/java/org/vafer/jdeb/ControlBuilder.java#L120 instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. I though about that too, but i didn't see a reliable way to detect binary files. In my case, the file is a shell script with a jar file appended. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the proper way to fix this is expanding https://github.com/tcurdt/jdeb/blob/master/src/main/java/org/vafer/jdeb/utils/InformationInputStream.java Right now we are only checking for the BOM and the shebang. We could also also try to detect a binary there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can you properly check for a binary there? Character codes >= 128? And by the way: what about shell scripts with "here documents" http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07_04. Maybe they have a similar problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't use BOM and Shebang but plain heuristics we indeed run into those problems with "here documents", too. I am wondering if we should take a step back here. Right now we have 2 types
Introducing a 3rd type is a bit sneaky as we would want to have variable expansion on only the shell part of the combined file. So question is whether there is another way to ship the jar but appending it to the shell script or having some kind of convention/marker that tells jdeb where to apply the variable expansion and what to copy as binary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not aware of an alternative place for the jar: is has to be present when postrm is executed. And at this point dpkg has removed all other files of the package. Even e.g. prerm. Is there a way to define a variables with my binary content? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not binary variables yet - but that's actually a very (!) interesting line of thinking to solve this. |
||
InputStream in = new FileInputStream(file); | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
Utils.copy(in, out); | ||
in.close(); | ||
out.close(); | ||
addControlEntry(file.getName().substring(0, file.getName().length() - 4), out.toByteArray(), outputStream); | ||
} else if (!"control".equals(file.getName())) { | ||
// initialize the information stream to guess the type of the file | ||
InformationInputStream infoStream = new InformationInputStream(new FileInputStream(file)); | ||
|
@@ -209,23 +216,25 @@ public BinaryPackageControlFile createPackageControlFile(File file, BigInteger p | |
|
||
|
||
private static void addControlEntry(final String pName, final String pContent, final TarArchiveOutputStream pOutput) throws IOException { | ||
final byte[] data = pContent.getBytes("UTF-8"); | ||
addControlEntry(pName, pContent.getBytes("UTF-8"), pOutput); | ||
} | ||
|
||
private static void addControlEntry(final String pName, final byte[] pData, final TarArchiveOutputStream pOutput) throws IOException { | ||
final TarArchiveEntry entry = new TarArchiveEntry("./" + pName, true); | ||
entry.setSize(data.length); | ||
entry.setSize(pData.length); | ||
entry.setNames("root", "root"); | ||
|
||
if (MAINTAINER_SCRIPTS.contains(pName)) { | ||
entry.setMode(PermMapper.toMode("755")); | ||
} else { | ||
entry.setMode(PermMapper.toMode("644")); | ||
} | ||
|
||
pOutput.putArchiveEntry(entry); | ||
pOutput.write(data); | ||
pOutput.write(pData); | ||
pOutput.closeArchiveEntry(); | ||
} | ||
|
||
/** | ||
* Tells if the specified directory is ignored by default (.svn, cvs, etc) | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make the tests work in my environment. Quick hack for me, Do not merge this, sorry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But probably hard to implement. I think you detect variables withing string - and have to encode them for saving the resulting file.
Another approach would be a configurable method you call before closing the tar file. I'd add my binary file in this method. And make my method availabe to your Code by adding a dependency to the Plugin config in my pom.