Prolog: I'm an idiot for missing this in the documentation
cmake-2.8.10.2
How do you make cmake preserve the original file permissions when installing a directory? For the project at hand, I'd like it to essentially copy some directories from my source tree to the install tree. To wit:
install(
DIRECTORY config runp
DESTINATION ${CMAKE_INSTALL_PREFIX}
PATTERN ".svn" EXCLUDE
PATTERN ".git" EXCLUDE
PATTERN "start_collection.snl" EXCLUDE
)
All works as expected -- except that executable scripts are getting copied in with incorrect file permissions. In fact, none of the original file permissions are preserved. Globally setting permissions using FILE_PERMISSIONS and DIRECTORY_PERMISSIONS is something I do not want to do, and frankly, would be a hack in this context.
In the shell-scripting world, I'd do something simple like this:
for i in config runp ; do
tar cf - $i | tar -C $CMAKE_INSTALL_PREFIX -xf -
done
Documentation suggests using USE_SOURCE_PERMISSIONS when calling install():
install(
DIRECTORY config runp
DESTINATION ${CMAKE_INSTALL_PREFIX}
USE_SOURCE_PERMISSIONS
PATTERN ".svn" EXCLUDE
PATTERN ".git" EXCLUDE
PATTERN "start_collection.snl" EXCLUDE
)
Alternatively, you can use install(PROGRAMS signature of this command. See docs for more info.
Related
I need to sync a local directory (destination) from the remote server directory (source) with the --delete option.
I've got this:
Local directory is /home/user/config and into it
removeit.txt
bar.csv
foo.h
config.conf
scripts <- Is a directory
logs <- Is adirectory
The remote directory is config and into it
bar.csv
foo.h
I want in the local directory after rsync
bar.csv
foo.h
config.conf
scripts <- Is a directory
logs <- Is adirectory
I've tested with multiple options but I can't get a entire rsync command with my needs.
rsync -avz --min-size=1 --delete -e "ssh" user#example.com:./config/ ./config --exclude ./config/scripts --exclude ./config/logs --exclude ./config/device.conf --dry-run
With a list of include files
rsync -avz --min-size=1 --include-from=list --exclude=* --delete-excluded -e "ssh" user#example.com:.config/ config/
But nothing works as I expected. The subfolders in the destination are deleted.
The man page for rsync has a section on "Include/Exclude Pattern Rules" which you should review. In particular, it looks like you are using ./ to refer to the directory relative of your shell's working directory which won't work the way you want.
Here is a relevant section of the documentation:
if the pattern starts with a / then it is anchored to a particular
spot in the hierarchy of files, otherwise it is matched against the
end of the pathname. This is similar to a leading ^ in regular
expressions. Thus /foo would match a name of "foo" at either the "root
of the transfer" (for a global rule) or in the merge-file's directory
(for a per-directory rule). An unqualified foo would match a name of
"foo" anywhere in the tree because the algorithm is applied
recursively from the top down; it behaves as if each path component
gets a turn at being the end of the filename. Even the unanchored
"sub/foo" would match at any point in the hierarchy where a "foo" was
found within a directory named "sub". See the section on ANCHORING
INCLUDE/EXCLUDE PATTERNS for a full discussion of how to specify a
pattern that matches at the root of the transfer.
The pattern you are using might be causing rsync to look for a folder literally called . which contains a file or folder called scripts or whatever.
Try replacing the relative-ish ./config/ part with / in your exclude patterns. That will anchor the pattern in the "root of transfer" which is the directory you are synchronizing. In other words, try this:
rsync -avz --min-size=1 --delete -e "ssh" user#example.com:./config/ ./config --exclude /scripts --exclude /logs --exclude /device.conf --dry-run
I hope that works. If it's not too late to check, please let me know if this worked for you.
Using any of the standard Robot libraries, is it possible to recursively copy the contents of a directory to an existing destination directory?
Basically, I'm looking for the equivalent of the following shell command: cp -r foo/. bar (note the trailing dot)
I tried Copy Directory but this creates a directory foo inside bar (as documented) and it doesn't stop doing that even when supplying the trailing dot. Copy Files chokes when it encounters a directory.
Is there anything I overlooked? Or do I need to just call cp -r myself?
As I only need this to work on Linux, I ended up implementing a custom keyword calling cp -r. If this is ever needed cross-platform, then I'll follow the suggestions to directly implement it in Python.
Copy Directory Contents
[Documentation] Recursively copies the contents of the source directory into the destination.
[Arguments] ${source} ${destination}
Directory Should Exist ${source}
Directory Should Exist ${destination}
${result} = Run Process cp -r ${source}/. ${destination}/
Should Be Equal As Integers ${result.rc} 0
I know this is a basic question but I'm missing something fundamental about makefiles.
Take this simple rule/action:
doc: ${SRC_DIR}/doc/dir1/file1.pdf ${SRC_DIR}/doc/dir1/file2.pdf
cp $? ${DEST_DIR}/doc/
the first time I run it, it copies file1.pdf and file2.pdf to the destination/doc directory. Perfect. I'm expecting the next time I run it, for it to do nothing. The source files haven't changed, aren't they a dependency? But when I run I get :
cp : cannot create regular file ..... :Permission denied.
so, 2 questions:
1) Why is it trying to do it again? When I run make -d I see it eventually says: No need to remake target .../file1.pdf and .../file2.pdf but then
it says : must remake target 'doc'
If it doesn't need to make either pdf file, why does it need to make doc?
2) say the pdf files had changed in the source, they are read only though, so it gets the permission denied error. How do you get around this?
A make rule:
target: preqreq0 prereq1...
command
...
says that target needs to be (re)made if it does not exist or is older than
any of the prerequisites preqreq0 prereq1..., and that target shall be
(re)made by running the recipe command ....
Your rule:
doc: ${SRC_DIR}/doc/dir1/file1.pdf ${SRC_DIR}/doc/dir1/file2.pdf
cp $? ${DEST_DIR}/doc/
never creates a file or directory doc, so doc will never exist when
the rule is evaluated (unless you create doc by other means), so the recipe
will always be run.
The kind of target that I believe you want doc to be is a phony target,
but you are going about it wrongly. A reasonable makefile for the purpose would
be:
SRC_DIR := .
DEST_DIR := .
PDFS := file1.pdf file2.pdf
PDF_TARGS := $(patsubst %,$(DEST_DIR)/doc/%,$(PDFS))
.PHONY: doc clean
doc: $(PDF_TARGS)
$(DEST_DIR)/doc/%.pdf: $(SRC_DIR)/doc/dir1/%.pdf
cp $< $#
clean:
rm -f $(PDF_TARGS)
I recommend The GNU Make documentation
As for your second problem, how to overwrite "readonly" files, it is unrelated to make.
You cannot overwrite files to which you do not have write permission, regardless
of the means by which you try to do it. You must get write permission to any files
that you need to write to. It is a system administration matter. If you do not
understand file permissions you may find help at sister-site Unix & Linux
or serverfault
I am using rdiff-backup. Really awesome simple powerful backup tool. However I am fighting with wildcard glob patterns. I have this directory structure:
/data/aaa/cache
/data/bbb/cache
/data/ccc/cache
etc....
In each cache directory are original files and cache files. Original files are named simply 1.jpg, 2.png, 3.gif, and so on. Cache files have some string attached to the original filename.
So I want to backup all the /data/*/cache directories, but to include only original files, not the cache files.
I am using this command:
rdiff-backup --exclude **/cache --include **/cache/+([0-9]).+([a-z]) /data /backup
But rdiff-backup returns this and I am lost:
Found interrupted initial backup. Removing...
Fatal Error: Last selection expression:
Command-line include glob: **/cache/+([0-9]).+([a-z])
only specifies that files be included. Because the default is to
include all files, the expression is redundant. Exiting because this
probably isn't what you meant.
You might want to do a two step process:
create a list of all files you want to exclude e.g. with find . -name "**/cache" > excludes.lst
use the list with --exclude-filelist excludes.lst
This way you can avoid fighting with the glob option and you have full control over your excludes
From http://rdiff-backup.nongnu.org/rdiff-backup.1.html :
A given file is excluded by the file selection system exactly
when the first matching file selection condition
specifies that the file be excluded; otherwise the file is included.
...
For instance,
rdiff-backup --include /usr --exclude /usr /usr /backup
is exactly the same as
rdiff-backup /usr /backup
because the include and exclude directives match exactly the same
files, and the --include comes first, giving it precedence.
So, in your case, it is complaining about the final --include because if a file gets there (i.e. it isn't matched by the previous --exclude) it will be included whether or not it matches the --include. That's what the error message was trying to say.
As for how to accomplish your goal...
Assuming you do want to exclude only paths of the form: /data/*/cache/[0-9]*.[a-z][a-z][a-z]?* just specify that:
rdiff-backup --exclude '/data/*/cache/[0-9]*.[a-z][a-z][a-z]?*' --exclude '*' /data /backup
This should work (I haven't tested it).
So this doesn't seem like a terribly complicated question I have, but it's one I can't find the answer to. I'm confused about what the -p option does in Unix. I used it for a lab assignment while creating a subdirectory and then another subdirectory within that one. It looked like this:
mkdir -p cmps012m/lab1
This is in a private directory with normal rights (rlidwka). Oh, and would someone mind giving a little explanation of what rlidwka means? I'm not a total noob to Unix, but I'm not really familiar with what this means. Hopefully that's not too vague of a question.
The man pages is the best source of information you can find... and is at your fingertips: man mkdir yields this about -p switch:
-p, --parents
no error if existing, make parent directories as needed
Use case example: Assume I want to create directories hello/goodbye but none exist:
$mkdir hello/goodbye
mkdir:cannot create directory 'hello/goodbye': No such file or directory
$mkdir -p hello/goodbye
$
-p created both, hello and goodbye
This means that the command will create all the directories necessaries to fulfill your request, not returning any error in case that directory exists.
About rlidwka, Google has a very good memory for acronyms :). My search returned this for example: http://www.cs.cmu.edu/~help/afs/afs_acls.html
Directory permissions
l (lookup)
Allows one to list the contents of a directory. It does not allow the reading of files.
i (insert)
Allows one to create new files in a directory or copy new files to a directory.
d (delete)
Allows one to remove files and sub-directories from a directory.
a (administer)
Allows one to change a directory's ACL. The owner of a directory can always change the ACL of a directory that s/he owns, along with the ACLs of any subdirectories in that directory.
File permissions
r (read)
Allows one to read the contents of file in the directory.
w (write)
Allows one to modify the contents of files in a directory and use chmod on them.
k (lock)
Allows programs to lock files in a directory.
Hence rlidwka means: All permissions on.
It's worth mentioning, as #KeithThompson pointed out in the comments, that not all Unix systems support ACL. So probably the rlidwka concept doesn't apply here.
-p|--parent will be used if you are trying to create a directory with top-down approach. That will create the parent directory then child and so on iff none exists.
-p, --parents
no error if existing, make parent directories as needed
About rlidwka it means giving full or administrative access. Found it here https://itservices.stanford.edu/service/afs/intro/permissions/unix.
mkdir [-switch] foldername
-p is a switch, which is optional. It will create a subfolder and a parent folder as well, even if parent folder doesn't exist.
From the man page:
-p, --parents no error if existing, make parent directories as needed
Example:
mkdir -p storage/framework/{sessions,views,cache}
This will create subfolder sessions,views,cache inside framework folder irrespective of whether 'framework' was available earlier or not.
PATH: Answered long ago, however, it maybe more helpful to think of -p as "Path" (easier to remember), as in this causes mkdir to create every part of the path that isn't already there.
mkdir -p /usr/bin/comm/diff/er/fence
if /usr/bin/comm already exists, it acts like:
mkdir /usr/bin/comm/diff
mkdir /usr/bin/comm/diff/er
mkdir /usr/bin/comm/diff/er/fence
As you can see, it saves you a bit of typing, and thinking, since you don't have to figure out what's already there and what isn't.
Note that -p is an argument to the mkdir command specifically, not the whole of Unix. Every command can have whatever arguments it needs.
In this case it means "parents", meaning mkdir will create a directory and any parents that don't already exist.