Search code examples
linuxsymlinkrpmcprhel6

Install rpm and put file into symbolic link directory


I have made an rpm package that install a program and one of the folders it needs to copy a file to is a symbolic link since the program the symbolic link is pointing to may change over time so it is easier to maintain the building of the rpm package by copying the file to the symbolic link rather then to the hard coded path. However, I get the error

cp: cannot overwrite directory with non-directory

when the rpm package tried to copy the file to the symbolic link folder. Why does this happen, and is there anything I can do to work around this error other then making the files to be copied to the folder the symbolic link points to? I am running RHEL 6.6 as of note.


Solution

  • That error generally means something like you having told cp to treat the target as a normal file (the -T argument).

    $ ls -lR
    .:
    total 16
    drwxr-xr-x 2 root root 4096 Feb  6 09:46 dir
    -rw-r--r-- 1 root root    0 Feb  6 09:45 file
    lrwxrwxrwx 1 root root    3 Feb  6 09:45 symdir -> dir
    
    ./dir:
    total 0
    $ cp -T file symdir
    cp: cannot overwrite non-directory `symdir' with non-directory
    $ ls -lR
    .:
    total 16
    drwxr-xr-x 2 root root 4096 Feb  6 09:46 dir
    -rw-r--r-- 1 root root    0 Feb  6 09:45 file
    lrwxrwxrwx 1 root root    3 Feb  6 09:45 symdir -> dir
    
    ./dir:
    total 0
    $ cp file symdir
    $ ls -lR
    .:
    total 16
    drwxr-xr-x 2 root root 4096 Feb  6 09:46 dir
    -rw-r--r-- 1 root root    0 Feb  6 09:45 file
    lrwxrwxrwx 1 root root    3 Feb  6 09:45 symdir -> dir
    
    ./dir:
    total 4
    -rw-r--r-- 1 root root 0 Feb  6 09:46 file