Index: less.admin.inc
===================================================================
RCS file: less.admin.inc
diff -N less.admin.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ less.admin.inc  1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,35 @@
+<?php
+// $Id: less.module,v 1.2.4.7 2010/12/09 03:22:13 coreym29 Exp $
+
+function less_settings(&$form_state) {
+  $form = array();
+  
+  $form['less_flush'] = array(
+    '#type' => 'fieldset',
+    '#collapsible' => FALSE,
+    '#value' => 'Click this button regenerate all LESS files once.'
+  );
+  
+  $form['less_flush']['flush'] = array(
+    '#type' => 'submit',
+    '#submit' => array('_flush_less'),
+    '#value' => 'Flush LESS files',
+  );
+  
+  $form['less_debug'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Less debug'),
+    '#description' => t('Enable the debug mode to make sure Less files are rendered to CSS files on every page load, regardless of any change done to the Less file (which may happen when using the @import notation, and changing only the imported file). Note that this setting does not override "Optimize CSS files" if set via <a href="@performance-url">Performance</a>.', array('@performance' => url('admin/settings/performance'))),
+    '#default_value' => variable_get('less_debug', FALSE),
+  );
+  
+  return system_settings_form($form);
+}
+
+function _flush_less($form, &$form_state) {
+  
+  $less_path = file_directory_path() . '/less';
+  _less_recursive_delete($less_path);
+  
+  drupal_set_message(t('LESS files flushed.'), 'status');
+}
Index: less.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/less/less.module,v
retrieving revision 1.2.4.7
diff -u -r1.2.4.7 less.module
--- less.module 9 Dec 2010 03:22:13 -0000 1.2.4.7
+++ less.module 15 Dec 2010 01:56:18 -0000
@@ -2,47 +2,69 @@
 // $Id: less.module,v 1.2.4.7 2010/12/09 03:22:13 coreym29 Exp $
 
 /**
+ * Implements hook_menu().
+ */
+function less_menu() {
+  $items = array();
+  
+  $items['admin/settings/less'] = array(
+    'title' => 'Less settings',
+    'description' => 'Administer Less settings',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('less_settings'),
+    'access arguments' => array('access administration pages'),
+    'file' => 'less.admin.inc',
+    'type' => MENU_NORMAL_ITEM,
+  );
+
+  return $items;
+}
+
+/**
  * Builds the less cache
  */
 function _less_build(&$vars, $hook) {
   
   $css = $vars['css'];
-  
-  $file_path = file_directory_path();
+
+  $less_path = file_directory_path() . '/less';
+
+  if (variable_get('less_debug', FALSE)) {
+    _less_recursive_delete($less_path);
+    drupal_set_message(t('LESS files are being regenerated on every request. Remember to <a href="!url">turn off</a> this feature on production websites.', array("!url" => url('admin/settings/less'))), 'status');
+  }
   
   foreach ($css as $media => $types) {
     foreach ($types as $type => $files) {
-      
+
       $files_keys = array_keys($files);
       foreach ($files_keys as $key => $input_file) {
-        
+
         if (substr($input_file, -5) == '.less') {
-          
-          $css_path = $file_path .'/less/'. dirname($input_file);
-          
+
+          $css_path = $less_path .'/'. dirname($input_file);
+
           if (!is_dir($css_path)) {
             @mkdir($css_path, 0775, TRUE);
           }
-          
+
           $output_file = $css_path .'/'. basename($input_file, '.less');
           if (substr($output_file, -4) != '.css') {
             $output_file .= '.css';
           }
-          $real_output_file = realpath($output_file);
-          
-          if (!file_exists($real_output_file) || filemtime(realpath($input_file)) > filemtime($real_output_file)) {
-            
+
+          if ((!file_exists($output_file) || filemtime($input_file) > filemtime($output_file))) {
             require_once('lessphp/lessc.inc.php');
-            
+
             $less = new lessc();
-            
+
             $contents = drupal_load_stylesheet($input_file, false);
-            
+
             $base = base_path() . dirname($input_file) .'/';
             _drupal_build_css_path(NULL, $base);
             // Prefix all paths within this CSS file, ignoring external and absolute paths.
             $data = preg_replace_callback('/url\([\'"]?(?![a-z]+:|\/+)([^\'")]+)[\'"]?\)/i', '_drupal_build_css_path', $contents);
-            
+
             try {
               $output_data = $less->parse($data);
               file_save_data($output_data, $output_file, FILE_EXISTS_REPLACE);
@@ -54,29 +76,28 @@
                 drupal_set_message($message, 'error');
               }
             }
-            
+
           }
-          
-          if (file_exists($real_output_file)) {
+
+          if (file_exists($output_file)) {
             array_splice($files_keys, $key, 1, $output_file);
           }
-          
+
         }
-        
+
       }
-      
+
       if (!empty($files)) {
         $css[$media][$type] = array_combine($files_keys, $files);
       }
-      
+
     }
   }
-  
+
   $vars['messages'] .= theme('status_messages');
-  
+
   $vars['css'] = $css;
   $vars['styles'] = drupal_get_css($vars['css']);
-  
 }
 
 /**
@@ -99,3 +120,30 @@
 function less_enable() {
   drupal_rebuild_theme_registry();
 }
+
+/**
+ * Recursively delete a path.
+ *
+ * Lifted from imagecache, with thanks to dopry/drewish.
+ */
+function _less_recursive_delete($path) {
+  if (is_file($path) || is_dir($path) || is_link($path)) {
+    if (is_file($path) || is_link($path)) {
+      unlink($path);
+    }
+    elseif (is_dir($path)) {
+      $d = dir($path);
+      while (($entry = $d->read()) !== FALSE) {
+        if ($entry == '.' || $entry == '..') continue;
+        $entry_path = $path .'/'. $entry;
+        _less_recursive_delete($entry_path);
+      }
+      $d->close();
+      rmdir($path);
+    }
+    else {
+      watchdog('LESS', 'Unknown file type(%path) stat: %stat ',
+                array('%path' => $path,  '%stat' => print_r(stat($path),1)), WATCHDOG_ERROR);
+    }
+  }
+}
