Remove a Symlink to a Directory

Remove a symlink to a directory


# this works:
rm foo
# versus this, which doesn't:
rm foo/

Basically, you need to tell it to delete a file, not delete a directory. I believe the difference between rm and rmdir exists because of differences in the way the C library treats each.

At any rate, the first should work, while the second should complain about foo being a directory.

If it doesn't work as above, then check your permissions. You need write permission to the containing directory to remove files.

In perforce, how to remove a symlink to a directory and add files in the same directory?

There does not seem to be anything preventing this:

C:\Perforce\test\dir>p4 opened
//stream/main/dir#1 - delete default change (symlink)
//stream/main/dir/bar#1 - add default change (text)
//stream/main/dir/foo#1 - add default change (text)

C:\Perforce\test\dir>p4 submit -d "presto"
Submitting change 106.
Locking 3 files ...
delete //stream/main/dir#2
add //stream/main/dir/bar#1
add //stream/main/dir/foo#1
Change 106 submitted.

Cannot remove symbolic link to directory

By putting a trailing slash you are referring to the directory the symlink points to, no longer the symlink itself. Printing the inode number (the number that a path refers to in the file system) shows the difference between dereferencing the symlink and the directory:

$ cd "$(mktemp --directory)"
$ mkdir a
$ stat --format %i a/
9
$ ln --symbolic a b
$ stat --format %i b
10
$ stat --format %i b/
9

This may be related to the fact that a symlink is never a directory, it is always just a file containing a path.

Remove-Item -Recurse -Force can't remove symlinks

The actual CMD equivalent to Remove-Item -Recurse -Force is:

cmd /c rmdir /s /q foo

as it will delete symlinks also in subdirectories. This seems to be good enough for me.

Removing and adding the same symlink in perforce

To modify a file in a single revision, use p4 edit instead of p4 add + p4 delete.



Related Topics



Leave a reply



Submit