cloc icon indicating copy to clipboard operation
cloc copied to clipboard

Error in git bash terminal(tar failed)

Open simahao opened this issue 2 years ago • 13 comments

Describe the bug Run cloc in git bash terminal, command like cloc --git --diff commit1 commit2 -v It looks like path with ":" lead tar command to failed. But I run same command in cmd terminal, it is ok.

error message: git ls-tree --name-only -r HEAD git ls-tree --name-only -r be6dd18 git archive -o C:\Users\xxx\AppData\Local\Temp\0pFsfzhh4N.tar be6dd18 "a.txt" git archive -o C:\Users\xxx\AppData\Local\Temp\KmV7o4ieoF.tar HEAD "b.txt" "d.txt" "test/c.txt" mkdir C:\Users\xxx\AppData\Local\Temp\0Kwe_O7SYd cd C:\Users\xxx\AppData\Local\Temp\0Kwe_O7SYd tar -xf "C:\Users\xxx\AppData\Local\Temp\0pFsfzhh4N.tar" tar: Cannot connect to C: resolve failed ...... Using temp file list [C:\Users\xxx\AppData\Local\Temp\ysQUS7WOX4] 0 text files. Using temp file list [C:\Users\xxx\AppData\Local\Temp\G27eOEuorp] 0 text files. 0 files ignored. Nothing to count.

cloc; OS; OS version

  • cloc version:1.96
  • If running the cloc source, Perl version:
  • OS (eg Linux, Windows, macOS, etc):windows
  • OS version:10

To Reproduce

Expected result

Additional context

simahao avatar Jul 29 '23 04:07 simahao

I have no difficulty running cloc in a git bash terminal. Can you point me to a public repo I can clone to reproduce? Tell me the exact commit entries also.

AlDanial avatar Jul 30 '23 04:07 AlDanial

Reopen if you have details on reproducing the problem

AlDanial avatar Aug 07 '23 01:08 AlDanial

Hey. I got the same problem but when I execute this command - tar -xvzf C:\\Test\files\my_file.tgz -C C:\Test\files

tar (child): Cannot connect to C: resolve failed when I run tests from git bash

v-osereda-jabil avatar Apr 15 '25 13:04 v-osereda-jabil

@v-osereda-jabil can you provide complete details of the steps you took? Which version of cloc? If you're counting a public repo, where can I download it?

AlDanial avatar Apr 19 '25 15:04 AlDanial

I have run into this issue myself today and have some more details. though I don't really know how or why it's happening.

The command I am running is:

cloc --diff abb39d57abe4bc0f10698ac2d6caaa16daa942da HEAD

This spits out the following output:

"C:/Users/roblo/scoop/apps/tar/current/bin/tar.exe": Cannot connect to C: resolve failed
"C:/Users/roblo/scoop/apps/tar/current/bin/tar.exe": Cannot connect to C: resolve failed
       0 text files.
       0 text files.
       0 files ignored.
Nothing to count.

This is being run against glektarssza/minecraft-player-handling-customizer from the feature/gtnh-support branch.

After checking the options out I noticed the existence of the --extract-with flag. Figuring something was wrong with tar on my system I tried to use 7-zip:

cloc --extract-with="7z x >FILE<" --diff abb39d57abe4bc0f10698ac2d6caaa16daa942da HEAD

This shed some light onto the situation.

7-Zip 24.09 (x64) : Copyright (c) 1999-2024 Igor Pavlov : 2024-11-29

Scanning the drive for archives:
1 file, 61440 bytes (60 KiB)

Extracting archive: C:\Users\roblo\AppData\Local\Temp\i4WNMkRbPs.tar
ERROR: C:\Users\roblo\AppData\Local\Temp\i4WNMkRbPs.tar
Cannot open the file as archive

The process cannot access the file because it is being used by another process.

Can't open as archive: 1
Files: 0
Size:       0
Compressed: 0

7-Zip 24.09 (x64) : Copyright (c) 1999-2024 Igor Pavlov : 2024-11-29

Scanning the drive for archives:
1 file, 112640 bytes (110 KiB)

Extracting archive: C:\Users\roblo\AppData\Local\Temp\6OVojULYYI.tar
ERROR: C:\Users\roblo\AppData\Local\Temp\6OVojULYYI.tar
Cannot open the file as archive

The process cannot access the file because it is being used by another process.

Can't open as archive: 1
Files: 0
Size:       0
Compressed: 0
       0 text files.
       0 text files.
       0 files ignored.
Nothing to count.

My guess is some kind of race condition that is causing cloc to be holding a file lock when the extractor tries to open the file?

glektarssza avatar Apr 30 '25 03:04 glektarssza

> cloc --version
2.04

for the record.

@AlDanial

glektarssza avatar Apr 30 '25 04:04 glektarssza

@glektarssza : that's an interesting insight, thanks. Is your experiment repeatable?

AlDanial avatar May 01 '25 04:05 AlDanial

@glektarssza : that's an interesting insight, thanks. Is your experiment repeatable?

Yes, it happens on my laptop too.

 > cloc --extract-with="7z x >FILE<" --git --diff c90083e56d6a31e2e1c6e0a908ad7af86f9a86c2 HEAD
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.

7-Zip 24.09 (x64) : Copyright (c) 1999-2024 Igor Pavlov : 2024-11-29

Scanning the drive for archives:
1 file, 0 bytes

Extracting archive: C:\Users\GLEKLA~1\AppData\Local\Temp\i4lhtc2mdj.zip
ERROR: C:\Users\GLEKLA~1\AppData\Local\Temp\i4lhtc2mdj.zip
Cannot open the file as archive

The process cannot access the file because it is being used by another process.

Can't open as archive: 1
Files: 0
Size:       0
Compressed: 0

7-Zip 24.09 (x64) : Copyright (c) 1999-2024 Igor Pavlov : 2024-11-29

Scanning the drive for archives:
1 file, 0 bytes

Extracting archive: C:\Users\GLEKLA~1\AppData\Local\Temp\vku5ZVkW33.zip
ERROR: C:\Users\GLEKLA~1\AppData\Local\Temp\vku5ZVkW33.zip
Cannot open the file as archive

The process cannot access the file because it is being used by another process.

Can't open as archive: 1
Files: 0
Size:       0
Compressed: 0
       0 text files.
       0 text files.
       0 files ignored.
Nothing to count.

Though, running just plain cloc I get a very different error:

 > cloc --git --diff c90083e56d6a31e2e1c6e0a908ad7af86f9a86c2 HEAD
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
[C:/Users/GLEKLA~1/AppData/Local/Temp/4HJ4LR3U7E.zip]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in C:/Users/GLEKLA~1/AppData/Local/Temp/4HJ4LR3U7E.zip,
        and cannot find C:/Users/GLEKLA~1/AppData/Local/Temp/4HJ4LR3U7E.zip.zip, period.
[C:/Users/GLEKLA~1/AppData/Local/Temp/QqI2DcBb5r.zip]
  End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.
unzip:  cannot find zipfile directory in C:/Users/GLEKLA~1/AppData/Local/Temp/QqI2DcBb5r.zip,
        and cannot find C:/Users/GLEKLA~1/AppData/Local/Temp/QqI2DcBb5r.zip.zip, period.
       0 text files.
       0 text files.
       0 files ignored.
Nothing to count.

For some reason it's trying to use unzip instead of tar, which I'm not sure why. Either way, it's still complaining about the file being in use by anther process which seems to be the same root problem.

glektarssza avatar May 01 '25 15:05 glektarssza

I was able to duplicate the problem on Windows. cloc has a subroutine, git_archive() that runs the (you guessed it) git archive command to save selected files to an archive. It uses the default format, tar, which probably isn't ideal on Windows. I'll experiment with the --format=zip option on Windows, see if that gets past the error.

AlDanial avatar May 04 '25 18:05 AlDanial

The latest commit, 814714e, helps but now the git archive command fails on a file with a problematic name, tests/inputs/issues/898/irregular"file2.md. This file actually causes other problems for git on Windows, even causes git pull and git clone of the cloc repo to fail. So I'll have to figure that out first...

AlDanial avatar Jun 06 '25 18:06 AlDanial

I'm at a loss. cloc now writes .zip archives on Windows but still getting "cannot access the file because it is being used by another process" from my extractor (I'm using 7-zip, specifically 7z x <zipfile>.

AlDanial avatar Jun 06 '25 19:06 AlDanial

@AlDanial If I had to theorize, it's probably something like Windows Defender checking the file and locking it in the process. Let me run a quick test to confirm. Is there some kind of flag I can use to set the temporary path that cloc will use for generating the archives? This way I can exclude that path from my anti-virus (Windows Defender, the built-in anti-virus in Windows, in my case).

glektarssza avatar Jun 07 '25 14:06 glektarssza

I've not had any luck in the anti-virus approach and inspecting the process with Process Monitor has yielded nothing that I can spot immediately that would point to an issue. Then again I'm not sure what I'm looking for so...

Here's a dump of my last set of logs, in CSV format, in case it's helpful @AlDanial. It should show the exact sequence of file system operations going on between cloc, git and 7z.

cloc-trace-failed-diff.CSV

glektarssza avatar Jun 07 '25 15:06 glektarssza