This file is indexed.

/usr/share/doc/libjcifs-java/examples/ThreadedSmbCrawler.java is in libjcifs-java-doc 1.3.19-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* examples for the jcifs smb client library in Java
 * Copyright (C) 2000  "Michael B. Allen" <jcifs at samba dot org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

import jcifs.smb.SmbFile;
import java.util.LinkedList;
import java.util.ListIterator;
import java.net.MalformedURLException;
import java.io.IOException;

public class ThreadedSmbCrawler {

    static int workingThreads = 0;

    class DirEntry {
        SmbFile dir;
        int depth;

        DirEntry( SmbFile dir, int depth ) {
            this.dir = dir;
            this.depth = depth;
        }
    }

    class SmbCrawlerThread extends Thread {

        StringBuffer sb = new StringBuffer();

        public void run() {
            while( true ) {
                try {
                    DirEntry e;

                    synchronized( dirList ) {
                        while( dirList.isEmpty() ) {
//System.err.println( "workingThreads=" + workingThreads );
                            if( workingThreads == 0 ) {
                                return; // done
                            }
                            dirList.wait( 2000 );
                        }
                        e = (DirEntry)dirList.remove( 0 );
                        if( e.depth == 0 ) {
                            continue;
                        }
                        workingThreads++;
                    }

                    SmbFile[] l = e.dir.listFiles();

                    int n = maxDepth - e.depth;

                    for(int i = 0; l != null && i < l.length; i++ ) {
                        try {
                            sb.setLength( 0 );
                            for( int k = 0; k < n; k++ ) {
                                sb.append( "    " );
                            }
                            SmbFile d = l[i];
                            System.err.println( sb.append( d ));
                            if( d.isDirectory() ) {
                                synchronized( dirList ) {
                                    dirList.add( new DirEntry( d, e.depth - 1 ));
                                    dirList.notify();
                                }
                            }
                        } catch( IOException ioe ) {
                            ioe.printStackTrace();
                        }
                    }
                    synchronized( dirList ) {
                        workingThreads--;
                    }
                } catch( Exception x ) {
                    synchronized( dirList ) {
                        workingThreads--;
                    }
                    x.printStackTrace();
                }
            }
        }
    }

    LinkedList dirList;
    int maxDepth, numThreads;
    Thread[] threads;

    ThreadedSmbCrawler( String dir, int maxDepth, int numThreads ) throws Exception {
        this.maxDepth = maxDepth;
        this.numThreads = numThreads;
        threads = new Thread[numThreads];
        dirList = new LinkedList();
        dirList.add( new DirEntry( new SmbFile( dir ), maxDepth ));
    }

    long go() throws Exception {
        int i;
        long start = System.currentTimeMillis();

        for( i = 0; i < numThreads; i++ ) {
            threads[i] = new SmbCrawlerThread();
            threads[i].start();
        }
        for( i = 0; i < numThreads; i++ ) {
            threads[i].join();
        }

        return System.currentTimeMillis() - start;
    }

    public static void main(String[] argv) throws Exception {
        ThreadedSmbCrawler tsc;

        if( argv.length < 3 ) {
            System.err.println( "usage: ThreadedSmbCrawler dir depth numThreads" );
            System.exit( 1 );
        }

        tsc = new ThreadedSmbCrawler( argv[0], Integer.parseInt( argv[1] ), Integer.parseInt( argv[2] ));
        System.err.println( "Crawling Complete: " + (tsc.go() / 1000) + "sec" );
    }
}