Skip to content

Commit 0e8b959

Browse files
committed
Add warning for dotfiles in info plugin
1 parent 5cb3117 commit 0e8b959

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

material/plugins/info/plugin.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,16 @@ def on_config(self, config):
214214

215215
# Create self-contained example from project
216216
files: list[str] = []
217+
dotpaths: list[str] = []
217218
with ZipFile(archive, "a", ZIP_DEFLATED, False) as f:
218219
for abs_root, dirnames, filenames in os.walk(os.getcwd()):
219220
# Set and print progress indicator
220221
indicator = f"Processing: {abs_root}"
221222
print(indicator, end="\r", flush=True)
222223

224+
# Track warning to decide if the indicator should be cleared
225+
warned = False
226+
223227
# Prune the folders in-place to prevent their processing
224228
for name in list(dirnames):
225229
# Resolve the absolute directory path
@@ -228,6 +232,12 @@ def on_config(self, config):
228232
# Exclude the directory and all subdirectories
229233
if self._is_excluded(path):
230234
dirnames.remove(name)
235+
continue
236+
237+
# Warn about .dotdirectories
238+
if _warn_on_dotpath(path):
239+
warned = True
240+
dotpaths.append(path)
231241

232242
# Write files to the in-memory archive
233243
for name in filenames:
@@ -238,12 +248,18 @@ def on_config(self, config):
238248
if self._is_excluded(path):
239249
continue
240250

251+
# Warn about .dotfiles
252+
if _warn_on_dotpath(path):
253+
warned = True
254+
dotpaths.append(path)
255+
241256
# Resolve the relative path to create a matching structure
242257
path = os.path.relpath(path, os.path.curdir)
243258
f.write(path, os.path.join(example, path))
244259

245260
# Clear the line for the next indicator
246-
print(" " * len(indicator), end="\r", flush=True)
261+
if not warned:
262+
print(" " * len(indicator), end="\r", flush=True)
247263

248264
# Add information on installed packages
249265
f.writestr(
@@ -309,6 +325,16 @@ def on_config(self, config):
309325
if buffer.nbytes > 1000000:
310326
log.warning("Archive exceeds recommended maximum size of 1 MB")
311327

328+
# Print warning when file contains hidden .dotpaths
329+
if dotpaths:
330+
print("List of potentially sensitive files:")
331+
for path in dotpaths:
332+
print(f" - {path}")
333+
log.warning(
334+
"Archive contains potentially sensitive dotfiles.\nPlease "
335+
"review and share only necessary data to reproduce the issue."
336+
)
337+
312338
# Aaaaaand done
313339
sys.exit(1)
314340

@@ -488,6 +514,15 @@ def _get_project_config(project_config_file: str):
488514

489515
return config
490516

517+
# Check if the path is a .dotpath, and issue a warning when that is the case.
518+
# The function also returns a boolean to track results outside it.
519+
def _warn_on_dotpath(path: str) -> bool:
520+
if path.rsplit(os.sep, 1)[-1].startswith("."):
521+
log.warning(f"The following .dotpath will be included: {path}")
522+
return True
523+
return False
524+
525+
491526
# -----------------------------------------------------------------------------
492527
# Data
493528
# -----------------------------------------------------------------------------

src/plugins/info/plugin.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,16 @@ def on_config(self, config):
214214

215215
# Create self-contained example from project
216216
files: list[str] = []
217+
dotpaths: list[str] = []
217218
with ZipFile(archive, "a", ZIP_DEFLATED, False) as f:
218219
for abs_root, dirnames, filenames in os.walk(os.getcwd()):
219220
# Set and print progress indicator
220221
indicator = f"Processing: {abs_root}"
221222
print(indicator, end="\r", flush=True)
222223

224+
# Track warning to decide if the indicator should be cleared
225+
warned = False
226+
223227
# Prune the folders in-place to prevent their processing
224228
for name in list(dirnames):
225229
# Resolve the absolute directory path
@@ -228,6 +232,12 @@ def on_config(self, config):
228232
# Exclude the directory and all subdirectories
229233
if self._is_excluded(path):
230234
dirnames.remove(name)
235+
continue
236+
237+
# Warn about .dotdirectories
238+
if _warn_on_dotpath(path):
239+
warned = True
240+
dotpaths.append(path)
231241

232242
# Write files to the in-memory archive
233243
for name in filenames:
@@ -238,12 +248,18 @@ def on_config(self, config):
238248
if self._is_excluded(path):
239249
continue
240250

251+
# Warn about .dotfiles
252+
if _warn_on_dotpath(path):
253+
warned = True
254+
dotpaths.append(path)
255+
241256
# Resolve the relative path to create a matching structure
242257
path = os.path.relpath(path, os.path.curdir)
243258
f.write(path, os.path.join(example, path))
244259

245260
# Clear the line for the next indicator
246-
print(" " * len(indicator), end="\r", flush=True)
261+
if not warned:
262+
print(" " * len(indicator), end="\r", flush=True)
247263

248264
# Add information on installed packages
249265
f.writestr(
@@ -309,6 +325,16 @@ def on_config(self, config):
309325
if buffer.nbytes > 1000000:
310326
log.warning("Archive exceeds recommended maximum size of 1 MB")
311327

328+
# Print warning when file contains hidden .dotpaths
329+
if dotpaths:
330+
print("List of potentially sensitive files:")
331+
for path in dotpaths:
332+
print(f" - {path}")
333+
log.warning(
334+
"Archive contains potentially sensitive dotfiles.\nPlease "
335+
"review and share only necessary data to reproduce the issue."
336+
)
337+
312338
# Aaaaaand done
313339
sys.exit(1)
314340

@@ -488,6 +514,15 @@ def _get_project_config(project_config_file: str):
488514

489515
return config
490516

517+
# Check if the path is a .dotpath, and issue a warning when that is the case.
518+
# The function also returns a boolean to track results outside it.
519+
def _warn_on_dotpath(path: str) -> bool:
520+
if path.rsplit(os.sep, 1)[-1].startswith("."):
521+
log.warning(f"The following .dotpath will be included: {path}")
522+
return True
523+
return False
524+
525+
491526
# -----------------------------------------------------------------------------
492527
# Data
493528
# -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)