Fix zip symlink problem.
1 parent 3c87ebd commit 8e2b94cbe0262c9b4ea21abbe506ae63a6bb260e
@Steven Schveighoffer Steven Schveighoffer authored on 21 Sep 2022
The Dlang Bot committed on 21 Sep 2022
Showing 1 changed file
View
16
source/dub/packagemanager.d
mkdirRecurse(dst_path.toNativeString());
} else {
if( !existsDirectory(dst_path.parentPath) )
mkdirRecurse(dst_path.parentPath.toNativeString());
// for symlinks on posix systems, use the symlink function to
// create them. Windows default unzip doesn't handle symlinks,
// so we don't need to worry about it for Windows.
version(Posix) {
import core.sys.posix.sys.stat;
if( S_ISLNK(cast(mode_t)a.fileAttributes) ){
import core.sys.posix.unistd;
// need to convert name and target to zero-terminated string
auto target = toStringz(cast(const(char)[])archive.expand(a));
auto dstFile = toStringz(dst_path.toNativeString());
enforce(symlink(target, dstFile) == 0, "Error creating symlink: " ~ dst_path.toNativeString());
goto symlink_exit;
}
}
 
{
auto dstFile = openFile(dst_path, FileMode.createTrunc);
scope(exit) dstFile.close();
dstFile.put(archive.expand(a));
}
setAttributes(dst_path.toNativeString(), a);
symlink_exit:
++countFiles;
}
}
logDebug("%s file(s) copied.", to!string(countFiles));