#StackBounty: #files #symlink #ext4 #delete #xattr How to make a symlink read only (`chattr +i /location/symlink`)?

Bounty: 50

How can we lock a symlink so it cannot be deleted?

With a normal file/directory chattr +i /file/location can achieve this but doing so with a symlink we get chattr: Operation not supported while reading flags on my-file.

There is a similar question, How to set chattr +i for my /etc/resolv.conf?, but without a solution that could be applied here.


Get this bounty!!!

#StackBounty: #command-line #files Conditional deleting of duplicate files

Bounty: 50

I have seen similar questions, but it seems my desired result is not covered in the answers.
I want to delete duplicates only if files share the same name.
Something like: rdfind -deleteduplicates true ~/folder will not accomplish my objective.

One idea could be to get the output (results.txt) of rdfind of a dry-run, and determine which files have the same name of the 1st one of each group, identified by beginning with: DUPTYPE_FIRST_OCCURRENCE XXXX

DUPTYPE_FIRST_OCCURRENCE 5148 2 37934240 2054 16916792 1 /home/fig3.tif
DUPTYPE_WITHIN_SAME_TREE -5148 3 37934240 2054 17044654 1 /home/other/fig3.tif
DUPTYPE_WITHIN_SAME_TREE -5148 3 35435435 2054 16546546 1 /home/other2/fig3.tif

DUPTYPE_FIRST_OCCURRENCE 5160 2 116397930 2054 16916804 1 /home/file.psd
DUPTYPE_WITHIN_SAME_TREE -5160 2 116397930 2054 16916870 1 /home/folder/file.psd
DUPTYPE_WITHIN_SAME_TREE -5160 2 116397930 2054 17654654 1 /home/folder/file2.psd

In the example above, for the 1st group 2 duplicates should be removed, while in the 2nd group only one should be removed, which has the same name as the First occurrence (file.psd).


Get this bounty!!!

#StackBounty: #8 #files How can I re-populate file_usage and file_managed tables?

Bounty: 100

I have a commerce website. I am also consuming a web service and creating corresponding products, including matching products with another table’s rows. I have the below code. It ran several times and I ended up deleting file references from file_usage and file_managed tables because the table had over 300.000 rows. The code used to work before I deleted did so. Since then I tried several things, including running a bare minimum. Since then, I’ve been pulling mt hair. What can I do to re-populate those tables?

<?php
$req = Drupal::httpClient()->get('http://www.example.com/path/to/web/service');
$res = $req->getBody();
$res = json_decode($res);
foreach($res->Data as $r) { 
  $query = Drupal::database()->select('excel', 'e')->fields('e')
    ->condition('stokkodu', $r->StokKodu);
  $or = $query->orConditionGroup()
    ->condition('grupindex', 1)
    ->condition('grupindex', NULL, 'IS NULL');
  $results = $query->condition($or)->execute()->fetchAll();
    foreach($results as $result) {
      $imagename = "public://urun".$result->gorsel;
      $images = Drupal::entityTypeManager()
        ->getStorage("file")
        ->loadByProperties(["uri" => $imagename]);
      $image = reset($images);
      if (!$image) {
      $image = File::create([
        'uri' => $imagename,
      ]);
      $image->save();
      $logoname = "public://urun/logo/".$result->logo;
      $logos = Drupal::entityTypeManager()
        ->getStorage("file")
        ->loadByProperties(["uri" => $logoname]);
      $logo = reset($logos);
      if (!$logo) {
        $logo = File::create([
          'uri' => $logoname,
        ]);
        $logo->save();
      } 
    }
  }
}


Get this bounty!!!

#StackBounty: #8 #files #plugins Field formatter module throws cannot declare class error

Bounty: 50

I am trying to write a custom module, which defines a field formatter plugin, but when I visit the Manage display page, I get this error:

Fatal error: Cannot declare class Drupalmy_formatterPluginFieldFieldFormatterMyFormatter, because the name is already in use in /var/www/sites/drupalroot/web/modules/custom/my_formatter/src/Plugin/Field/FieldFormatter/MyFormatter.php on line 0

I’ve compared my module to several other working field formatter plugins and can’t seem to figure out what I’m missing.

My module directory is laid out like this:

web/modules/custom/my_formatter/
├── my_formatter.info.yml
├── my_formatter.module
├── src
│   └── Plugin
│       └── Field
│           └── FieldFormatter
│               └── MyFormatter.php
└── templates
    └── my-formatter.html.twig

My info file:

name: My Formatter
type: module
description: 'Do some fun stuff.'
package: Field types
core: 8.x
dependencies:
  - field
  - file

And my MyFormatter.php file:

<?php
/**
 * @file
 * Contains Drupalmy_formatterPluginFieldFieldFormatterMyFormatter.
 */

namespace Drupalmy_formatterPluginFieldFieldFormatter;

use DrupalCoreFieldFieldItemListInterface;
use DrupalfilePluginFieldFieldFormatterFileFormatterBase;

/**
 * Plugin implementation of the 'my' formatter.
 *
 * @FieldFormatter(
 *   id = "my",
 *   label = @Translation("My Formatter"),
 *   field_types = {
 *     "file"
 *   }
 * )
 */
class MyFormatter extends FileFormatterBase {

  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = [];
    foreach ($items as $delta => $item) {
      $elements[$delta] = [
        '#theme' => 'my_formatter',
        '#my_var' => 'Hello',
      ];
    }
    return $elements;
  }

}

Any help would be greatly appreciated.


Get this bounty!!!

#StackBounty: #8 #files Field formatter module throws cannot declare class error

Bounty: 50

I am trying to write a custom module, which defines a field formatter plugin, but when I visit the Manage display page, I get this error:

Fatal error: Cannot declare class Drupalmy_formatterPluginFieldFieldFormatterMyFormatter, because the name is already in use in /var/www/sites/drupalroot/web/modules/custom/my_formatter/src/Plugin/Field/FieldFormatter/MyFormatter.php on line 0

I’ve compared my module to several other working field formatter plugins and can’t seem to figure out what I’m missing.

My module directory is laid out like this:

web/modules/custom/my_formatter/
├── my_formatter.info.yml
├── my_formatter.module
├── src
│   └── Plugin
│       └── Field
│           └── FieldFormatter
│               └── MyFormatter.php
└── templates
    └── my-formatter.html.twig

My info file:

name: My Formatter
type: module
description: 'Do some fun stuff.'
package: Field types
core: 8.x
dependencies:
  - field
  - file

And my MyFormatter.php file:

<?php
/**
 * @file
 * Contains Drupalmy_formatterPluginFieldFieldFormatterMyFormatter.
 */

namespace Drupalmy_formatterPluginFieldFieldFormatter;

use DrupalCoreFieldFieldItemListInterface;
use DrupalfilePluginFieldFieldFormatterFileFormatterBase;

/**
 * Plugin implementation of the 'my' formatter.
 *
 * @FieldFormatter(
 *   id = "my",
 *   label = @Translation("My Formatter"),
 *   field_types = {
 *     "file"
 *   }
 * )
 */
class MyFormatter extends FileFormatterBase {

  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = [];
    foreach ($items as $delta => $item) {
      $elements[$delta] = [
        '#theme' => 'my_formatter',
        '#my_var' => 'Hello',
      ];
    }
    return $elements;
  }

}

Any help would be greatly appreciated.


Get this bounty!!!

#StackBounty: #files #logs #dovecot #large-files Split large log file based on date criteria, while logging facility is running

Bounty: 50

the log file is /var/log/dovecot.info, >4GB, with date format:

2019-07-01 01:07:40

My objective is:

  • have the /var/log/dovecot.info which starts with 2019-01-01 00:00:00 and contains up to now log entries
  • have the /var/log/dovecot.info.old which contains log entries before 2019-01-01 00:00:00 (cca 67% of them)
  • operation performed without shutting the dovecot daemon if possible

I’ve tried with grep and tail with offset, no luck. I also do not know if this can be done without shutting down the dovecot safely.


Get this bounty!!!

#StackBounty: #files #logs #large-files Split large log file based on date criteria, while logging facility is running

Bounty: 50

the log file is /var/log/dovecot.info, >4GB, with date format:

2019-07-01 01:07:40

My objective is:

  • have the /var/log/dovecot.info which starts with 2019-01-01 00:00:00 and contains up to now log entries
  • have the /var/log/dovecot.info.old which contains log entries before 2019-01-01 00:00:00 (cca 67% of them)
  • operation performed without shutting the dovecot daemon if possible

I’ve tried with grep and tail with offset, no luck. I also do not know if this can be done without shutting down the dovecot safely.


Get this bounty!!!