[PATCH 2/2] journal view of external media, avoid symlink loops [0.84]
James Cameron
quozl at laptop.org
Mon Sep 6 22:41:18 EDT 2010
Inserting external media such as an operating system filesystem and then
selecting the volume in journal leads to extra delay and many errors in
shell.log, caused by symlink loops being followed.
This patch detects symlinks, and:
* avoids following symlinks to ".",
* avoids following symlinks to a point higher in the same path.
---
src/jarabe/journal/model.py | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py
index c60349d..afaecb6 100644
--- a/src/jarabe/journal/model.py
+++ b/src/jarabe/journal/model.py
@@ -19,7 +19,7 @@ import os
from datetime import datetime
import time
import shutil
-from stat import S_IFMT, S_IFDIR, S_IFREG
+from stat import S_IFLNK, S_IFMT, S_IFDIR, S_IFREG
import traceback
import re
@@ -331,7 +331,15 @@ class InplaceResultSet(BaseResultSet):
continue
full_path = dir_path + '/' + entry
try:
- stat = os.stat(full_path)
+ stat = os.lstat(full_path)
+ if S_IFMT(stat.st_mode) == S_IFLNK:
+ link = os.readlink(full_path)
+ if link == '.':
+ continue
+ if link.startswith('/') and full_path.startswith(link):
+ continue
+ stat = os.stat(full_path)
+
if S_IFMT(stat.st_mode) == S_IFDIR:
self._pending_directories += 1
gobject.idle_add(lambda s=full_path: self._recurse_dir(s))
--
1.7.1
--zYM0uCDKw75PZbzx--
More information about the Sugar-devel
mailing list