From 3185a90f11fed36461d74d9b2abccc7cd21e0bf8 Mon Sep 17 00:00:00 2001
From: Bob Vincent <bobvin@pillars.net>
Date: Thu, 11 Aug 2011 09:35:27 -0400
Subject: [PATCH 1/2] Issue #1241184: Check for directory existence before
 calling file_unmanaged_delete_recursive()

---
 less.module |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/less.module b/less.module
index 4556e6ff17c446b635bb251d228b6f28b78aa0b0..a4f3c791f81d646878849213fce56397f50e9dcd 100644
--- a/less.module
+++ b/less.module
@@ -64,7 +64,9 @@ function _less_pre_render($styles) {
 
   // Flush compiled LESS files if developer mode is enabled
   if (variable_get('less_devel', FALSE)) {
-    file_unmanaged_delete_recursive($less_path);
+    if (is_dir($less_path)) {
+      file_unmanaged_delete_recursive($less_path);
+    }
     if (user_access(LESS_PERMISSION) && flood_is_allowed('less_devel_warning', 1)) {
       flood_register_event('less_devel_warning');
       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/config/development/less'))), 'status');
@@ -151,7 +153,9 @@ function less_flush_caches() {
   if (!drupal_static('less_cron')) {
     // Delete all generated files.
     $less_path = file_default_scheme() . '://less';
-    file_unmanaged_delete_recursive($less_path);
+    if (is_dir($less_path)) {
+      file_unmanaged_delete_recursive($less_path);
+    }
   }
   return array();
 }
-- 
1.7.6.238.g11ac1.dirty


From 4369d00da1810c065a5a507565987be725e1db59 Mon Sep 17 00:00:00 2001
From: Bob Vincent <bobvin@pillars.net>
Date: Thu, 11 Aug 2011 10:23:49 -0400
Subject: [PATCH 2/2] Issue #1246308: Allow setting the path for processed CSS
 files.

---
 less.admin.inc |    8 +++++++-
 less.install   |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 less.module    |   23 +++--------------------
 3 files changed, 63 insertions(+), 21 deletions(-)
 create mode 100644 less.install

diff --git a/less.admin.inc b/less.admin.inc
index ead8395e9b30567d910b559cc8a62fd651298daf..a1e7e05785af8a3d3cea0b3a0ecc1f0944d717f6 100644
--- a/less.admin.inc
+++ b/less.admin.inc
@@ -7,13 +7,19 @@
  */
 
 function less_settings($form, &$form_state) {
-
   $form['less_flush'] = array(
     '#type' => 'fieldset',
     '#collapsible' => FALSE,
     '#value' => 'Click this button regenerate all LESS files once.',
   );
 
+  $form['less_path'] = array(
+    '#type' => 'textfield',
+    '#title' => t('LESS path'),
+    '#description' => t('Choose a directory path for storing compiled CSS files. This directory and its contents will be deleted and re-created whenever LESS files are regenerated.'),
+    '#default_value' => variable_get('less_path', 'public://less'),
+  );
+
   $form['less_flush']['flush'] = array(
     '#type' => 'submit',
     '#submit' => array('_flush_less'),
diff --git a/less.install b/less.install
new file mode 100644
index 0000000000000000000000000000000000000000..c5bd9adcbeae303ec1a20bbdd633754aa3d4bca1
--- /dev/null
+++ b/less.install
@@ -0,0 +1,53 @@
+<?php
+/**
+ * Support installation and uninstallation of LESS module.
+ */
+
+/**
+ * Implements hook_requirements().
+ *
+ * Ensures that the selected path for storing processed CSS is writable.
+ *
+ * @param $phase The phase in which hook_requirements is run: install or runtime.
+ */
+function less_requirements($phase) {
+  if ($phase == 'install') {
+    return array();
+  }
+  $result['less'] = array(
+    'title' => t('LESS'),
+  );
+  $args = array('!url' => url('admin/config/development/less'));
+  $less_path = variable_get('less_path', 'public://');
+  if (!file_prepare_directory($less_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
+    $result['less'] += array(
+      'value' => t('Invalid path'),
+      'description' => t('The directory path for storing compiled CSS files is invalid.  Visit the <a href="!url">LESS settings page</a> to correct this error.', $args),
+      'severity' => REQUIREMENT_WARNING,
+    );
+  }
+  elseif (variable_get('less_devel', FALSE)) {
+    $result['less'] += array(
+      'value' => t('Developer mode enabled'),
+      'description' => t('LESS files are being regenerated on every request. Remember to <a href="!url">turn off</a> this feature on production websites.', $args),
+    $result['less']['severity'] = 
+      'severity' => REQUIREMENT_WARNING,
+    );
+  }
+  else {
+    $result['less'] += array(
+      'value' => 'Ok',
+      'description' => 'The LESS CSS preprocessor is functioning normally.',
+      'severity' => 'REQUIREMENT_OK',
+    );
+  }
+  return $result;
+}
+
+/**
+ * Implements hook_uninstall().
+ */
+function less_uninstall() {
+  variable_del('less_path');
+  variable_del('less_devel');
+}
diff --git a/less.module b/less.module
index a4f3c791f81d646878849213fce56397f50e9dcd..635f3ed2cb815230f4ebe74e2410c2296d7e7715 100644
--- a/less.module
+++ b/less.module
@@ -60,7 +60,7 @@ function _less_pre_render($styles) {
     $lessphp_include = 'lessphp/lessc.inc.php';
   }
   
-  $less_path = file_default_scheme() . '://less';
+  $less_path = variable_get('less_path', 'public://less');
 
   // Flush compiled LESS files if developer mode is enabled
   if (variable_get('less_devel', FALSE)) {
@@ -152,7 +152,7 @@ function _less_pre_render($styles) {
 function less_flush_caches() {
   if (!drupal_static('less_cron')) {
     // Delete all generated files.
-    $less_path = file_default_scheme() . '://less';
+    $less_path = variable_get('less_path', 'public://less');
     if (is_dir($less_path)) {
       file_unmanaged_delete_recursive($less_path);
     }
@@ -165,24 +165,7 @@ function less_flush_caches() {
  */
 function less_cron_queue_info() {
   drupal_static('less_cron', TRUE);
-}
-
-/**
- * Implementation of hook_requirements().
- *
- * @param $phase The phase in which hook_requirements is run: install or runtime.
- */
-function less_requirements($phase) {
-  if ($phase == 'runtime' && variable_get('less_devel', FALSE)) {
-    return array(
-      'LESS' => array(
-        'title' => 'LESS',
-        'value' => 'Developer mode enabled',
-        'description' => 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'))),
-        'severity' => REQUIREMENT_WARNING,
-      ),
-    );
-  }
+  return array();
 }
 
 function less_element_info_alter(&$type) {
-- 
1.7.6.238.g11ac1.dirty

