1

I'm trying to call 'git clone' from a C++ program in Windows, to do that I create an empty folder (using std::filesystem::create_directory and _chdir) then I use CreateProcessW this way:

::CreateProcessW(std::wstring(fullPath.begin(), fullPath.end()).c_str(),
                            const_cast<LPWSTR>(std::wstring(fullArgs.begin(), fullArgs.end()).c_str()),
                            nullptr,
                            nullptr,
                            TRUE,
                            _createNewConsole ? CREATE_NEW_CONSOLE : 0,
                            nullptr,
                            std::wstring(_path.begin(), _path.end()).c_str(),
                            &siStartInfo,
                            &piProcInfo);

But when I do that Git returns me the following error message:

fatal: could not create work tree dir 'XXXX': Permission denied

However since I created the folder myself I'm not sure what is the issue
Folder perms are the following:

drwxr-xr-x

Any idea how to solve that?

Xwilarg
  • 364
  • 1
  • 6
  • 16
  • Unrelated: Why the `const_cast`? Create the temporary `wstring` before you call `CreateProcess` and supply that using it's `data()` member function instead. What type is `fullPath`? If it's a `wstring`, why not use `fullPath.c_str()` directly? Does your `fullArgs` include a quoted (`""`) version of `lpApplicationName`? – Ted Lyngmo Jun 24 '20 at 18:14
  • 1
    `drwxr-xr-x` has very little to do with MS-Windows permissions. Right-click the directory > Properties > Security and examine the effective security for the user running the program. – Richard Critten Jun 24 '20 at 18:19
  • 1
    @RichardCritten OP could be running in a WSL I guess. – Ted Lyngmo Jun 24 '20 at 18:55
  • fullPath is a std::string, fullArgs is the name of the executable and the arguments, separated by an empty space. About the const_cast it's because the c_str() give me a const wchar_t* and I didn't manage to get rid of the const – Xwilarg Jun 24 '20 at 21:10
  • Also about the Security tab, I checked the permissions and every users have everything needed in it – Xwilarg Jun 24 '20 at 21:13
  • `fullArgs.data()` gives you access to the same `wchar_t*` as `fullArgs.c_str()`, only non-`nonst`. But, if `fullPath` is a `std::string` what does the resulting `wstring` look like after you've converted a `string` to a `wstring` like that? I think that's where it's broken [Demo](https://godbolt.org/z/C43-yF) – Ted Lyngmo Jun 25 '20 at 13:14
  • I removed the const_cast thanks to data(), about the wstring, I tried using ::CreateProcessA (who takes a string instead of a wstring) and I still have the same error – Xwilarg Jun 25 '20 at 13:28
  • If you did that, did you also change `fullArgs` to be a `std::string`? Is directory name is actually `XXXX`? – Ted Lyngmo Jun 25 '20 at 17:55
  • Yeah I changed everything to std::string, XXXX is the folder that git clone is trying to create (and even if I create it before it doesn't change anything) – Xwilarg Jun 25 '20 at 18:16

1 Answers1

0

Try with

chmod -R 777 yourfolder

Polivicio
  • 71
  • 1
  • 1
  • 12
  • Since when can you find the *chmod* command, on a Microsoft Windows PC (as specified in the question)? – Sam Varshavchik Jun 24 '20 at 18:13
  • 1
    @SamVarshavchik WSL probably. `drwxr-xr-x` gave me that feeling, – Ted Lyngmo Jun 24 '20 at 18:16
  • Actually I'm using git bash that allow me to do some Linux commands such as chmod, however chmod -R 777 didn't change the perms of the folder (it's still drwxr-xr-x). – Xwilarg Jun 24 '20 at 21:04
  • @Xwilarg try to give a look to this [question](https://stackoverflow.com/questions/25730041/updating-file-permissions-with-git-bash-on-windows-7) – Polivicio Jun 25 '20 at 07:00
  • Looks like this only apply to files since it says Windows guess if it can launch them depending of the extension. Also I tried to look at the permissions using icacls and it looks that all users already have full control on the folder – Xwilarg Jun 25 '20 at 13:32