Hifidelio-User.de

Das (inoffizielle!) Forum für Hifidelio-User
Aktuelle Zeit: 20.10.2017 14:43

Alle Zeiten sind UTC + 1 Stunde [ Sommerzeit ]




Ein neues Thema erstellen Auf das Thema antworten  [ 28 Beiträge ]  Gehe zu Seite Vorherige  1, 2
Autor Nachricht
 Betreff des Beitrags:
BeitragVerfasst: 30.01.2008 09:16 
Offline
Godfather of Hifidelio
Benutzeravatar

Registriert: 03.02.2005 12:45
Beiträge: 2040
Wohnort: Rheinhessen
gigi hat geschrieben:
Well, what samba now does is to build an almost human-unreadable hash whenever a filename with forbidden characters arises. Why not do both - replace forbidden characters with a _ *and* adding a (maybe shorter) hash value to the name?

Yes, I consider SAMBA's strategy rather braindead and a source of constant trouble.

Maybe just renumbering within SAMBA actually is a sufficient strategy: If that same name is created afterwards, I would again renumber my "virtual" name. A client may end up in the wrong directory, but on the other hand, a change on the server has happened, so this is probably expected behaviour anyway.

To sum up the strategy:
- Scan the file names for "forbidden" characters
- If one is found, simply skip it (I wouldn't replace it with a strange character)
- Renumber the name afterwards until it is unique
- Upon retransmission of names generated this way, re-renumber

When renumbering, preserve file extensions.

_________________
Verallgemeinerungen sind generell schlecht.


Nach oben
 Profil  
 
 Betreff des Beitrags:
BeitragVerfasst: 30.01.2008 10:17 
Offline
Benutzeravatar

Registriert: 16.08.2005 08:58
Beiträge: 216
Wohnort: Heppenheim
gigi hat geschrieben:
Well, what samba now does is to build an almost human-unreadable hash whenever a filename with forbidden characters arises. Why not do both - replace forbidden characters with a _ *and* adding a (maybe shorter) hash value to the name?

Probably a good idea, but fails for file names with maximum length. However, for most filenames this would be a nice solution. But I have never fiddled with the SAMBA source, so I have no idea how difficult it is to implement this.

Thomas


Nach oben
 Profil  
 
 Betreff des Beitrags:
BeitragVerfasst: 30.01.2008 10:19 
Offline
Benutzeravatar

Registriert: 16.08.2005 08:58
Beiträge: 216
Wohnort: Heppenheim
Musikuss hat geschrieben:
Maybe just renumbering within SAMBA actually is a sufficient strategy: If that same name is created afterwards, I would again renumber my "virtual" name. A client may end up in the wrong directory, but on the other hand, a change on the server has happened, so this is probably expected behaviour anyway.

I am not sure if a one-way mapping is sufficient. Mapping a non-windows filename to a valid windows filename can be done using many different ways, but doesn't samba have to map the mapped filenames back to the original filenames as well? If Hallo? and Hallo_ become Hallo1 and Hallo2, how do you know that upon accessing Hallo1 you need to use Hallo? and not Hallo_ ?

Thomas


Nach oben
 Profil  
 
 Betreff des Beitrags:
BeitragVerfasst: 30.01.2008 11:27 
Offline
Benutzeravatar

Registriert: 22.02.2007 01:03
Beiträge: 441
I once tried the mangled map option but couldn't get it to work properly

Zitat:
mangled map
If the default behavior of name mangling is not sufficient, you can give Samba further instructions on how to behave using the mangled map option. This option allows you to specify mapping patterns that can be used in place of name mangling performed by Samba. For example:

[data]
mangled map =(*.database *.db) (*.class *.cls)
Here, Samba is instructed to search each encountered file for characters that match the first pattern specified in the parenthesis and convert them to the modified second pattern in the parenthesis for display on an 8.3 client. This is useful in the event that name mangling converts the filename incorrectly or converts it to a format that the client cannot understand readily. Patterns are separated by whitespaces.


_________________
the Rough Guide to the Hifidelio has become part of The Well Tempered Computer


Nach oben
 Profil  
 
 Betreff des Beitrags:
BeitragVerfasst: 30.01.2008 17:22 
Offline
Godfather of Hifidelio
Benutzeravatar

Registriert: 03.02.2005 12:45
Beiträge: 2040
Wohnort: Rheinhessen
tobox hat geschrieben:
I am not sure if a one-way mapping is sufficient. Mapping a non-windows filename to a valid windows filename can be done using many different ways, but doesn't samba have to map the mapped filenames back to the original filenames as well? If Hallo? and Hallo_ become Hallo1 and Hallo2, how do you know that upon accessing Hallo1 you need to use Hallo? and not Hallo_ ?

Yes of course: the samba server has to keep track of its mappings. But it has to anyway, no matter what strategy it uses.

_________________
Verallgemeinerungen sind generell schlecht.


Nach oben
 Profil  
 
 Betreff des Beitrags:
BeitragVerfasst: 06.04.2008 23:03 
Offline

Registriert: 04.03.2006 01:02
Beiträge: 39
Wohnort: London UK
I have updated my perl script to fix a bug where it didn't work when only the second or later album for an artist contained a filename that needed fixing.

There is one outstanding issue which is where you have artists that only differ in case (e.g. Ministry of Sound and Ministry Of Sound). Ideally you should only have a single name but if you have more than one then Windows will only see one of them.

- Simon.


Nach oben
 Profil  
 
 Betreff des Beitrags:
BeitragVerfasst: 16.04.2008 15:53 
Offline
Benutzeravatar

Registriert: 30.11.2005 12:16
Beiträge: 53
Wohnort: Chaos-City
brookheather hat geschrieben:
I have updated my perl script to fix a bug where it didn't work when only the second or later album for an artist contained a filename that needed fixing.

There is one outstanding issue which is where you have artists that only differ in case (e.g. Ministry of Sound and Ministry Of Sound). Ideally you should only have a single name but if you have more than one then Windows will only see one of them.

- Simon.


where I can get your perl script to download? and do you have a short instruction to install it at the Hifidelio?

Cheers
Gerhard


Nach oben
 Profil  
 
 Betreff des Beitrags:
BeitragVerfasst: 16.04.2008 16:38 
Offline

Registriert: 04.03.2006 01:02
Beiträge: 39
Wohnort: London UK
GKroadking hat geschrieben:
where I can get your perl script to download? and do you have a short instruction to install it at the Hifidelio?


You can copy the code from the first post on this topic into a file and then copy it to the import directory and follow the instructions.


Nach oben
 Profil  
 
 Betreff des Beitrags:
BeitragVerfasst: 09.05.2008 18:06 
Offline

Registriert: 18.09.2005 03:02
Beiträge: 73
Hello,

today I tried to used the script for the first time, but when I tried to execute the script the file can't be found and an error message appears ("bad interpreter: No such file or directory")

Bild

My config:
PC: WinXP Prof, SP2
Hifidelio: firmware version 2.3.21 pro, HD 500GB

So what did I do wrong ? I don't know why the file can't be found ?!


Nach oben
 Profil  
 
 Betreff des Beitrags:
BeitragVerfasst: 09.05.2008 18:15 
Offline
Moderator

Registriert: 27.01.2005 21:11
Beiträge: 2436
what does
Code:
ls /usr/bin/perl

say?

There are various different perl versions at the hifidelio, depending on SW versions you installed in the past.

Try to change the first line in the script to
Code:
#!/opt/perl/bin/perl


Good luck!


Nach oben
 Profil  
 
 Betreff des Beitrags:
BeitragVerfasst: 09.05.2008 18:16 
Offline
Godfather of Hifidelio
Benutzeravatar

Registriert: 03.02.2005 12:45
Beiträge: 2040
Wohnort: Rheinhessen
Try calling perl:
Code:
perl /audio/import/musiclink.pl

Maybe you will have to call perl using its complete path. I don't remember that right now.

_________________
Verallgemeinerungen sind generell schlecht.


Nach oben
 Profil  
 
 Betreff des Beitrags:
BeitragVerfasst: 09.05.2008 18:28 
Offline

Registriert: 18.09.2005 03:02
Beiträge: 73
Musikuss hat geschrieben:
Try calling perl:
Code:
perl /audio/import/musiclink.pl

Maybe you will have to call perl using its complete path. I don't remember that right now.


Thanks a lot Musikuss, using

Code:
perl /audio/import/musiclink.pl


it works :-) And I didn't have to call perl using its complete path.

@gigi: It also didn't work with changing the first line of the script to

Code:
#!/opt/perl/bin/perl


But thanks for your quick responses :-)


Nach oben
 Profil  
 
BeitragVerfasst: 08.10.2012 01:48 
Offline

Registriert: 31.05.2005 22:35
Beiträge: 6
I want to share my version of musiclink.p
Implemented are some of the suggestions made by brookheather, musikuss and tobox in this thread.

Features:

- filenames are unique, file extensions are kept, files that differ only in case are displayed
- invalid characters are skipped: both ":? and *<|>\
- all filenames/directorynames are changed, not only those with invalid characters
- no symbolic links to directories are created, a new directory is created instead
- preserve the timestamp of a newly created directory
- script must be called with directoryname of musicdir, usually /audio/music, allowing other directories
- script runs faster

Todo:

Script adds inode number to filenames to make them unique but does not check if max. length (?) is reached.
(Although I have never encountered any problems ...)

Example:

For file /audio/music/Amy Winehouse/Frank/03 F**k Me Pumps.mp3
a linkname /audio/music/.music/Amy Winehouse-3457025/Frank-3457026/03 Fk Me Pumps-3457032.mp3
is created. Where 3457025, 3457026 and 3457032 are the inode numbers.

Code:
#!/usr/bin/perl

# musiclinks.p
#-------------------------------------------------------------------------------
# Hifidelio script for creating symbolic links to music files with invalid
# Windows names.
#
# see hifidelio user forum:
#
#   Perl script to remap Linux filenames to Windows format
#   http://www.hifidelio-user.de/viewtopic.php?t=4044
#
# Usage:
#
#   perl -w musiclinks.p <musicdirectory>
#
# Example:
#
#   cd /audio/music
#   perl -w musiclinks.p /audio/music
#
#   Creates the linkdir /audio/music/.music with windows-friendly names.
#-------------------------------------------------------------------------------

use strict;
use warnings;
use FileHandle;

# global variables
my $release = '0.5'       ;
my $reldate = '2012-10-06';
my $author  = 'maikl'     ;

main();

#-------------------------------------------------------------------------------
# main routine
#
# - check parameters
# - remove old linkdir and create again
# - call ProcessDir to recursively process musicdir and its subdirectories
#   and create symbolic links in linkdir
#-------------------------------------------------------------------------------
sub main
{
  my $workingdir;
  my $musicdir  ;
  my $linkdir   ;
  my $cnt       ;

  $workingdir = $ENV{PWD};
  print "workingdir=$workingdir...\n";

  $cnt = @ARGV ;
  die "usage: perl -w musiclinks.p <musicdirectory>\n" if ($cnt != 1);

  $musicdir = shift @ARGV;
  print "  musicdir=$musicdir...\n";

  die "directory $musicdir does not exist\n" if (! -d $musicdir) ;

  $linkdir = sprintf( "%s/.music", $workingdir );
  print "   linkdir=$linkdir...\n";

  if (-d $linkdir)
    {
      print "   rm -r $linkdir...\n" ;
      system( "rm -r $linkdir" );
      die "could not delete directory $linkdir...\n" if (-d $linkdir)
    }

  print "   creating directory $linkdir...\n";
  mkdir( $linkdir, 0777 ) || die "could not create directory $linkdir...\n";

  ProcessDir( $musicdir, $linkdir );
}


#-------------------------------------------------------------------------------
# - called recursively
# - begin scan in sourcedir
# - create directories in destdir using built-in cmd mkdir
# - create symbolic links to files using built-in cmd symlink
# - call CheckName to build unique and windows-friendly filenames
# - set timestamp for newly created directories
#-------------------------------------------------------------------------------
sub ProcessDir
{
  my ($sourcedir, $destdir) = @_;
  my $file  ;
  my @files ;

  chdir($sourcedir) || die "unable to chdir to $sourcedir...\n";

  @files = <*>;   
  foreach $file (@files)
  {
    if (-d $file) 
    {
      my $newfile       = CheckName($file);
      my $nextsourcedir = sprintf( "%s/%s", $sourcedir, $file  );
      my $nextdestdir   = sprintf( "%s/%s", $destdir, $newfile );

      # always create directory with inode name,
      # no longer create symbolic links to directories

      mkdir( $nextdestdir, 0777 ) || die "could not create directory $nextdestdir...\n";

      ProcessDir( $nextsourcedir, $nextdestdir );

      chdir( $sourcedir );
    }
    else
    {
      my $newfile = CheckName($file);

      print " symlink: $destdir/$newfile -> $sourcedir/$file\n" ;

      # symlink ( old, new ); create symbolic link
      symlink(  "$sourcedir/$file" , "$destdir/$newfile" )
              || die "could not create link to $sourcedir/$file\n";
    }
  }
 
  if (-d $destdir)
  {
    my @StatusInfo = stat( $sourcedir );

    print "   utime: set timestamp for directory $destdir\n" ;

    # utime (atime, mtime, name); set timestamp for name
    utime( $StatusInfo[8], $StatusInfo[9], $destdir );
  }
}


#-------------------------------------------------------------------------------
# - check parameter $filename for invalid windows characters
# - skip invalid chars
# - remove trailing '.'
# - insert "-$inode" to filename matching "(.*)\.(.*)$" thus keeping the
#   extension, in all other cases append "-$inode"
# - return $newfilename
#-------------------------------------------------------------------------------
sub CheckName
{
  my ($filename)  = @_ ;
  my $newfilename = '' ;

  my @chars     ;
  my $char      ;
  my $inode = '';

  $inode = (stat($filename))[1]  ;

  @chars = split( '', $filename );

  # remove trailing .
  if ($chars[-1] eq '.' )
  {
    pop(@chars);
  }

  foreach $char (@chars)
  {
    # skip invalid chars
    next if ($char eq '?'  );
    next if ($char eq ':'  );
    next if ($char eq '"'  );
    next if ($char eq '*'  );
    next if ($char eq '\\' );
    next if ($char eq '<'  );
    next if ($char eq '>'  );
    next if ($char eq '|'  );
   
    $newfilename = $newfilename . $char;
  }

  if (-d $filename)
  {
    $newfilename = $newfilename . "-$inode" ;
  }
  else
  {
    if ($newfilename =~ m"(.*)\.(.*$)" )
    {
      $newfilename = $1 . "-$inode." . $2;
    }
    else
    {
      $newfilename = $newfilename . "-$inode" ;
    }
  }

  $newfilename;
}


Nach oben
 Profil  
 
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 28 Beiträge ]  Gehe zu Seite Vorherige  1, 2

Alle Zeiten sind UTC + 1 Stunde [ Sommerzeit ]


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.

Suche nach:
Gehe zu:  
cron
Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de