# work directories containing files unable to be removed



## Oclair (Oct 7, 2022)

Any ideas?

Running portsnap throws some odd errors...

Removing old files and directories... rm: /usr/ports/lang/gnatcross-sysroot-aarch64/work/lib/libc.so.7: Operation not permitted
rm: /usr/ports/lang/gnatcross-sysroot-aarch64/work/lib/libthr.so.3: Operation not permitted
rm: /usr/ports/lang/gnatcross-sysroot-aarch64/work/lib/libcrypt.so.5: Operation not permitted
rm: /usr/ports/lang/gnatcross-sysroot-aarch64/work/lib: Directory not empty
rm: /usr/ports/lang/gnatcross-sysroot-aarch64/work/usr/lib/librt.so.1: Operation not permitted
rm: /usr/ports/lang/gnatcross-sysroot-aarch64/work/usr/lib: Directory not empty
rm: /usr/ports/lang/gnatcross-sysroot-aarch64/work/usr: Directory not empty
rm: /usr/ports/lang/gnatcross-sysroot-aarch64/work: Directory not empty
rm: /usr/ports/lang/gnatcross-sysroot-aarch64: Directory not empty


----------



## im (Oct 7, 2022)

I think it is a flag like schg.
Try to check it using`ls -lo`

Example:

```
# ll -lo /lib
-r--r--r--  1 root  wheel  schg 1981952 Apr  9  2021 libc.so.7
-r--r--r--  1 root  wheel  -     210600 Apr  9  2021 libcam.so.7
-r--r--r--  1 root  wheel  -      23280 Apr  9  2021 libcasper.so.1
-r--r--r--  1 root  wheel  schg   51960 Apr  9  2021 libcrypt.so.5
```

You can remove flags using chflags().
`chflags noschg filename`


----------



## T-Daemon (Oct 8, 2022)

Removing the work directory  (`make clean`  or `rm -r work`) would resolve the issue.

EDIT: This would fail, see next posting.


----------



## T-Daemon (Oct 8, 2022)

im said:


> I think it is a flag like schg.


It's exactly a file flag issue.

I  checked the port what would be build, it just downloads a aarch64 base.txz (see highlighted section below) and extracts some directories from the tarball (`EXTRACT_AFTER_ARGS=     lib/ usr/include/ usr/lib/`):

```
# cd /usr/ports/lang/gnatcross-sysroot-aarch64/

# make fetch-list
mkdir -p /usr/ports/distfiles/gnatcross/arm64-aarch64/R11_3 && cd /usr/ports/distfiles/gnatcross/arm64-aarch64/R11_3 &&
{ env /usr/bin/fetch -Fpr  -S 97990888 ftp://ftp.freebsd.org/pub/FreeBSD/releases/arm64*/aarch64/11.3-RELEASE/base.txz*  ||
 env /usr/bin/fetch -Fpr  -S 97990888 http://distcache.FreeBSD.org/ports-distfiles/gnatcross/arm64-aarch64/R11_3/base.txz  ||
 echo "base.txz" not fetched; }
```

It looks like the ports `post-extract` didn't work here:

/usr/ports/lang/gnatcross-sysroot-aarch64/Makefile

```
post-extract:
        /bin/chflags -R noschg ${WRKDIR}
```



im said:


> You can remove flags using chflags().
> `chflags noschg filename`


Instead of chflags(1) each file separately, run the command recursively, `chflags -R 0 work` (or `chflags -R noschg work`), then `make clean` (or `rm -r work`).

Besides the failed post-extract, 11.3-RELEASE is EoL. Who wants to use the port (package) should file a bug report.


----------



## Oclair (Oct 31, 2022)

Hey, thank you for all the support for this issue I was experiencing.

I figured out that it was related to kern_securelevel

I had the following in /etc/rc.conf
kern_securelevel_enable="YES"
kern_securelevel="2"

As with updating the OS changing chflags is not possible under this mode of kern_securelevel

Thanks again, and have a nice day!


----------

