Skip to content

Commit 3b3bd59

Browse files
committed
Implement solution (append unc prefix) to fix the longpath issue when using genattrib.py in Windows OS. However, the test is still failing.
1 parent 1a183c4 commit 3b3bd59

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

about_code_tool/genattrib.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@
2525
import csv
2626
import errno
2727
import logging
28+
import ntpath
2829
import optparse
2930
import os
31+
import posixpath
3032
import sys
3133

3234
from os.path import exists, dirname, join, abspath, isdir, basename, expanduser, normpath
33-
35+
from about_code_tool.about import on_windows
3436
from about import Collector
3537
import genabout
38+
import about
3639

3740
LOG_FILENAME = 'error.log'
3841

@@ -147,16 +150,27 @@ def extract_zip(location):
147150
archive_base_name = os.path.basename(location).replace('.zip', '')
148151
base_dir = tempfile.mkdtemp()
149152
target_dir = os.path.join(base_dir, archive_base_name)
153+
target_dir = about.add_unc(target_dir)
150154
os.makedirs(target_dir)
151155

156+
if target_dir.endswith((ntpath.sep, posixpath.sep)):
157+
target_dir = target_dir[:-1]
158+
152159
with zipfile.ZipFile(location) as zipf:
153160
for info in zipf.infolist():
154161
name = info.filename
155162
content = zipf.read(name)
156163
target = os.path.join(target_dir, name)
157-
if not os.path.exists(os.path.dirname(target)):
158-
os.makedirs(os.path.dirname(target))
159-
if not content and target.endswith(os.path.sep):
164+
is_dir = target.endswith((ntpath.sep, posixpath.sep))
165+
if is_dir:
166+
target = target[:-1]
167+
parent = os.path.dirname(target)
168+
if on_windows:
169+
target = target.replace(posixpath.sep, ntpath.sep)
170+
parent = parent.replace(posixpath.sep, ntpath.sep)
171+
if not os.path.exists(parent):
172+
os.makedirs(parent)
173+
if not content and is_dir:
160174
if not os.path.exists(target):
161175
os.makedirs(target)
162176
if not os.path.exists(target):

about_code_tool/tests/test_genattrib.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import os
2020
import unittest
2121

22-
from about_code_tool import genattrib
22+
from about_code_tool import genattrib, about
2323

2424
from about_code_tool.tests.test_about import get_temp_file
2525

@@ -111,7 +111,7 @@ def test_genattrib_basic_with_filter(self):
111111
not_expected = [
112112
'Annotator 1.2.10',
113113
'component_4',
114-
'djangosnippets.org_2413 2011-04-12',
114+
'djangosnippets.org_2413 2011-04-12',
115115
]
116116
for ex in not_expected:
117117
self.assertFalse(ex in result, ex)
@@ -136,7 +136,6 @@ def test_genattrib_from_zipped_dir(self):
136136
for ex in expected:
137137
self.assertTrue(ex in result, ex)
138138

139-
140139
def test_genattrib_zip_with_filter(self):
141140
self.maxDiff = None
142141
# note: this contains an about_files subdir that is the root of all ABOUT files in the "project"
@@ -158,11 +157,18 @@ def test_genattrib_zip_with_filter(self):
158157
not_expected = [
159158
'Annotator 1.2.10',
160159
'component_4',
161-
'djangosnippets.org_2413 2011-04-12',
160+
'djangosnippets.org_2413 2011-04-12',
162161
]
163162
for ex in not_expected:
164163
self.assertFalse(ex in result, ex)
165164

165+
def test_extract_deep_zip(self):
166+
test_zip = 'about_code_tool/tests/testdata/longpath.zip'
167+
extracted = genattrib.extract_zip(test_zip)
168+
unc_extracted = about.add_unc(extracted)
169+
for root, dirs, files in os.walk(unc_extracted):
170+
self.assertTrue('non-supported_date_format.ABOUT' in files)
171+
166172
def genattrib_command_tester(args, options):
167173
parser = genattrib.get_parser()
168174
options, args = parser.parse_args(args, options)

0 commit comments

Comments
 (0)