Opened 5 years ago

Last modified 4 years ago

#13369 new Bugs

[Windows] Cannot handle symbolic links

Reported by: 0x0c0ff33.1523@… Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.66.0 Severity: Problem
Keywords: bug, filesystem, error, symlink, shortcut Cc:

Description

I wanted to port my application from Linux to Windows, but shortcut handling is not working.

Symlink creation, resolution and detection is not possible on my Windows 10 (Version 1709).

Tested with Boost 1.66.0 and 1.64.0.

Compiled the Boost Libraries with MSVC (Version 19.10.25019 for x86 and x64).

Getting the exception "boost::filesystem::create_symlink: A required privilege is not held by the client"

Example:

#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;

int main(){
	try{
		fs::create_symlink("/path/to_target", "/path/to/link");
	}
	
	catch(const std::exception& err){
		std::cerr << err.what() << '\n';
	}
}

Also boost::fileystem::canonical() is not working for me. Tested with extensions ".lnk" and ".url" and without extension, gives me the path to the symbolic link itself (with .lnk), otherwise path not found.

int main(){
	fs::path path = "/path/to/shortcut";

	for(const auto& ext : {"", ".lnk", ".url"}){
		try{
			std::cout << fs::canonical(path.string() + ext) << '\n';
		}

		catch(const std::exception& err){
			std::cerr << err.what() << '\n';
		}
	}

Also symlinks cannot be detected by fs::is_symlink() on my Windows system.

int main(){
	fs::path path = "/path/to/shortcut";

	for(const auto& ext : {"", ".lnk", ".url"}){
		auto s = fs::symlink_status(path.string() + ext);
		std::cout << (s.type() == fs::file_type::symlink_file) << ',' << fs::is_symlink(s) << '\n';
	}
}

Returns always false.

Change History (1)

comment:1 by emenchen@…, 4 years ago

Shortcuts are not that same as symbolic links. Creating a symbolic link used to require Administrator privileges, although apparently you can do it now if you put the machine in Developer Mode. https://blogs.windows.com/buildingapps/2016/12/02/symlinks-windows-10/

I don't think there is any bug here.

Note: See TracTickets for help on using tickets.