Is there a way to copy a directory full of files and change their file extentions in a Dockerfile - dockerfile

Problem
I want to copy all the files in a directory over to my container, changing the extension.
Setup
Lets say I want my local directory src/* copied into the container at /work/
src/ contains a bunch of files with extensions like .txt.
I want to COPY them over and change their extensions to .textfile.
Currently I am doing
COPY src/file1.txt /work/file1.textfile
COPY src/file2.txt /work/file2.textfile
COPY src/file3.txt /work/file3.textfile
...
This works file but create a bunch of layers in my image and I'd like to just have it done in one step.
What I've tried
COPY src/*.text /work/*.textfile
This doesn't work.
Work around
I installed util-linux and used the rename command like so:
COPY src/*.txt /work/
RUN rename '.txt' '.textfile' /work
But this is undesirable as the command comes as a package.
Question
Is there a way to do this simply as a dockerfile command?

Related

Conan package manager - how to remove folders during conan install?

I have a local conanfile.py to consume a package, the package is already located on the local cache (~/.conan/).
In the conanfile.py there is the imports() function in which I copy some files from the package into my build folder.
I have two files with the same name in different directories and I copy them to the same directory and rename one of them.
After I do that, I am left with an empty directory I want to remove, but can't find a way to do so from conanfile.py, every attempt seems to remove the folder before the files gets run. My imports looks as follows:
class SomeConanPkg(ConanFile):
name = "SomeName"
description = "SomeDesc"
requires = (
"SomePkg/1.0.0.0#SomeRepo/stable")
def imports(self):
# copy of 1st file
self.copy("somefile.dll", src=os.path.join("src"), dst=os.path.join(build_dest))
# copy of 2nd file to nested directory
self.copy("somefile.dll", src=os.path.join("src", "folder"), dst=os.path.join(build_dst, "folder"))
# move and rename the file to parent directory
shutil.copy2(os.path.join(build_dst, "folder", "somefile.dll"), os.path.join(build_dst, "renamed_file.dll"))
# now build_dst/folder is an empty directory
I have tried to use conan tools.rmmdir() or just calling shutil.rmmtree() but all of them seems to run before the files gets copied.
I also tried to add a package() or deploy() member functions and execute the remove inside but these methods don't seem to run at all (verified with a debug print).
Any ideas?
I ended us solving it in the package creation side.
Renamed the files as I wanted and then just consumed them
Try conan remove <package name> . If you do not know the exact package name you can also use conan search to see the list of packages before you use conan remove.

Is there a way with conan to export an empty directory?

Considering a folder (called parent_folder) containing an empty folder (called empty_son_folder) and another one that is not empty (called not_empty_son_folder) and the following exports_sources method:
exports_sources = ["parent_folder*"]
Only not_empty_son_folder is exported.
Is there a way with conan to force to copy an empty folder in export source method?
As #Yumnosch said it is possible to add a dummy file to force conan to include this folder or create this folder later in the receipe (#drodri's solution).
If the need is to have files generated by some test programs, both solutions work.
It is also possible to create such a folder directly in the test program that needs it.

cmake - how do i do add_cd_file but for directories

I am trying to add cygwin to the reactos project. everytime i try doing
add_cd_file(${CMAKE_CURRENT_SOURCE_DIR}/cygwin DESTINATION reactos/cygwin FOR all)
It fails because it is not a file, I have tried to use copy but that just copies the file, it does not add it to the destination. So my question is how do I do something like this add_cd_dir?

Installing OpenCart extensions locally

When installing OpenCart extensions, you´re generally given a bunch of folders that should be copied to the root directory and the extension files will find their way to the right subfolders. This works great in FTP software, but on a local installation (Mac OSX) using Finder, this operation makes Finder want to overwrite the folders completely, deleting the actual site and just keep the extension.
I can hold Alt when dragging the folders and it will give me the option to not overwrite, the problem is I have hidden files visible, which means there's now a .DS_STORE file in each folder and the ”Hold ALT”-approach doesn’t work in case there are ANY duplicate files in any of the folders.
I’m sure someone out there has stumbled upon the same problem, any ideas for how to solve such a simple but annoying problem? I do not wish to use FTP software for local file management.
I have the same problem, and i found 3 different ways to solve this:
a - use another file manager, i personally use "Transmit" to do this sort of things;
b - use terminal, like: ditto <source> <destination>. Or easier way just type ditto, and drag the source folder, then drag the destination folder, all inside source will merge inside destination;
c - unzip the plugin, inside the OC folder using the terminal, like: tar -zxvf plugin.zip;

Using %{buildroot} in a SPEC file

I'm creating a simple RPM installer, I just have to copy files to a directory structure I create in the %install process.
The %install process is fine, I create the following folder /opt/company/application/ with the command mkdir -p %{buildroot}/opt/company/%{name} and then I proceed to copy the files and subdirectories from my package. I've tried to install it and it works.
The doubt I have comes when uninstalling. I want to remove the folder /opt/company/application/ and I thought you're supposed to use %{buildroot} anywhere when referencing the install location. Because my understanding is the user might have a different structure and you can't assume that rmdir /opt/company/%{name}/ will work. Using that command in the %postun section deletes succesfully the directories whereas using rmdir ${buildroot}/opt/company/%{name} doesn't delete the folders.
My question is, shouldn't you be using ${buildroot} in the %postun in order to get the proper install location? If that's not the case, why?
Don't worry about it. If you claim the directory as your own in the %files section, RPM will handle it for you.
FYI, %{buildroot} probably won't exist on the target machine.