<commit_before>#
# Cookbook Name:: cron
# Provider:: d
#
# Copyright 2010-2015, Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

use_inline_resources

action :delete do
  file "/etc/cron.d/#{new_resource.name}" do
    action :delete
    notifies :create, 'template[/etc/crontab]', :delayed if node['cron']['emulate_cron.d']
  end
end

action :create do
  # We should be able to switch emulate_cron.d on for Solaris, but I don't have a Solaris box to verify
  fail 'Solaris does not support cron jobs in /etc/cron.d' if node['platform_family'] == 'solaris2'
  create_template(:create)
end

action :create_if_missing do
  create_template(:create_if_missing)
end

def create_template(create_action)
  template "/etc/cron.d/#{new_resource.name}" do
    cookbook new_resource.cookbook
    source 'cron.d.erb'
    mode new_resource.mode
    variables(
      name: new_resource.name,
      predefined_value: new_resource.predefined_value,
      minute: new_resource.minute,
      hour: new_resource.hour,
      day: new_resource.day,
      month: new_resource.month,
      weekday: new_resource.weekday,
      command: new_resource.command,
      user: new_resource.user,
      mailto: new_resource.mailto,
      path: new_resource.path,
      home: new_resource.home,
      shell: new_resource.shell,
      comment: new_resource.comment,
      environment: new_resource.environment
    )
    action create_action
    notifies :create, 'template[/etc/crontab]', :delayed if node['cron']['emulate_cron.d']
  end
end
<commit_msg>Sanitized dots from cron filename. [Closes #70]<commit_after>#
# Cookbook Name:: cron
# Provider:: d
#
# Copyright 2010-2015, Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

use_inline_resources

sanitized_filename = new_resource.name.gsub('.', '-')

action :delete do
  file "/etc/cron.d/#{sanitized_filename}" do
    action :delete
    notifies :create, 'template[/etc/crontab]', :delayed if node['cron']['emulate_cron.d']
  end
end

action :create do
  # We should be able to switch emulate_cron.d on for Solaris, but I don't have a Solaris box to verify
  fail 'Solaris does not support cron jobs in /etc/cron.d' if node['platform_family'] == 'solaris2'
  create_template(:create)
end

action :create_if_missing do
  create_template(:create_if_missing)
end

def create_template(create_action)
  template "/etc/cron.d/#{sanitized_filename}" do
    cookbook new_resource.cookbook
    source 'cron.d.erb'
    mode new_resource.mode
    variables(
      name: sanitized_filename,
      predefined_value: new_resource.predefined_value,
      minute: new_resource.minute,
      hour: new_resource.hour,
      day: new_resource.day,
      month: new_resource.month,
      weekday: new_resource.weekday,
      command: new_resource.command,
      user: new_resource.user,
      mailto: new_resource.mailto,
      path: new_resource.path,
      home: new_resource.home,
      shell: new_resource.shell,
      comment: new_resource.comment,
      environment: new_resource.environment
    )
    action create_action
    notifies :create, 'template[/etc/crontab]', :delayed if node['cron']['emulate_cron.d']
  end
end

{'fraction_non_alphanumeric': 0.09515819750719079, 'fraction_numerical': 0.006711409395973154, 'mean_word_length': 3.8523255813953488, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1249679', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1277, 'n_words': 406}