2

I have the following code inside a spec file:

mkdir -p %{buildroot}%{_qt6_bindir}
pushd %{buildroot}%{_qt6_bindir}
for i in * ; do
  case "${i}" in
    qdbuscpp2xml|qdbusxml2cpp|qtpaths)
      ln -v  ${i} %{buildroot}%{_bindir}/${i}-qt6
      ;;
    *)
      ln -v  ${i} %{buildroot}%{_bindir}/${i}
      ;;
  esac
done
popd

when i run build i got following error:

ln: target '/home/abuild/rpmbuild/BUILDROOT/qt6-qtbase-6.4.3-1.x86_64/usr/bin/qtpaths6': Not a directory

where qtpath6 is an excutable file. how to fix this error?

  • Does the file already exist and you want to override it? Use `-f` flag. Are you positive that you want hard links rather than symbolic links? – treuss Mar 28 '23 at 17:59
  • yes the file already exists! and yes i want hard link and i tried -f also same error.. – Ahmed Moselhi Mar 28 '23 at 18:02
  • How about just including `rm -f %{buildroot}%{_bindir}/${i}-qt6` before the `ln -v ...` line? – treuss Mar 28 '23 at 18:10
  • tried but same error! – Ahmed Moselhi Mar 28 '23 at 18:41
  • Which RH/CentOS version are you using? I haven't worked with rpmbuild for a while, but checked some old .spec files and they all do `rm -rf %{buildroot}` instead of trying to overwrite. – treuss Mar 29 '23 at 18:12

2 Answers2

1

What's going on is that a component of the target path is not a directory. I can reproduce the problem like this:

$ ln /etc/hosts/foo bar
ln: failed to access '/etc/hosts/foo': Not a directory

That's because /etc/hosts is a file. I picked that well-known file to make it obvious.

(The wording of the diagnostic is not exactly the same in my version of ln as you can see.)

What's probably happening is that ln calls the link system call, which fails with a -1 and an errno of ENOTDIR. The program just translates that error to Not a directory via strerror, and attributes the error to the target path as such.

We know that ln cannot possibly be complaining that the target isn't a directory, because that is specifically disallowed: you cannot make a hard link to a directory!

$ ln /etc ./etc
ln: /etc: hard link not allowed for directory
Kaz
  • 55,781
  • 9
  • 100
  • 149
0

I think the answer is simply: "Spec files are not any form of scripting language", as answered here.

treuss
  • 1,913
  • 1
  • 15